473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Excel VBA VLookup assitance

maxamis4
295 Expert 100+
I am building a VBA code that I need to lookup multiple values into another sheet. The second part to this is I have a table which I filter programmatically and I only want the vlookup to match the values in that table that are filtered and return a salary value. Based on that this is what i have come up with after doing some reading but obviously not working the way it should.

What i have posted is not the complete function, just the portion I am trying to get working.
Expand|Select|Wrap|Line Numbers
  1.  
  2.     Set wks = Worksheets("tblINR144")  'define the sheet where the data I am looking for is
  3.     Set Rng = Wks.Range("H:W")  ' Define the columns that identify the range.
  4.  
  5.     Set SrcWks = Worksheets("Payroll") 
  6.     Set Rng2 = SrcWks.Range("A4:B200")
  7.  
  8.     Application.ScreenUpdating = False
  9.     Application.DisplayAlerts = False
  10.  
  11.     Sheets("PAYROLL").Select 'Currnet sheet where I have the value values that in need to find in payroll
  12.  
  13.     For Each cl In Rng2
  14.  
  15.         If z > 1 Then
  16.  
  17.             s1 = SrcWks.Cells(z, 1).Value
  18.             s2 = SrcWks.Cells(z, 2).Value
  19.  
  20.             ' Call the Vlookup function to look up the rate of pay for the supplied employee name. This
  21.             ' returns the value from the second column of the range A1:B8 within the current worksheet.
  22.  
  23.              s3 = Application.WorksheetFunction.VLookup(s1 & s2, Rng.SpecialCells(xlCellTypeVisible), 10, False)
  24.  
  25.  
  26.            .......
  27.  
  28.            ........
  29.  
  30.            ....................
  31.  
  32.      Next cl
  33.  
  34.  
  35.  

FILTER APPLIED on DRFlag inside the table

value1 = EmployeeName
Value2 = objCode

Return value = BasePay


Sample Table
EmployeeName Title GradeStep Series IPNo MasterRecordNumber FundCode OrgCode Program Project Task DRFlag ObjCode ObjDescription HoursWorked BasePay

Name 1 title1 5 11-1 n/a n/a 0000 000001 test testing 4 21 230 testing data 23 223.00
Name 1 title1 5 11-1 n/a n/a 0000 000001 test testing 4 22 231 testing data 23 253.00
Name 2 title1 2 10-9 n/a n/a 0000 000001 test testing 4 20 230 testing data 23 123.00
Name 3 title1 6 07-0 n/a n/a 0000 000001 test testing 4 21 234 testing data 23 23.00
Jan 8 '17 #1
0 2392

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rebecca | last post by:
could someone tell me the correct syntax for using vlookup in visual basic
0
NeoPa
by: NeoPa | last post by:
VlookUp or Vertical LookUp is a function that enables Excel to ‘Find’ related items from within a range stored elsewhere. Elsewhere can mean another excel workbook on another PC, but can also mean a...
5
by: catlover30 | last post by:
HI, I need help with excel VLOOKUP! I am at a new job and really trying to solve this without asking anyone at work, since they seem th expect me to know this. What I am trying to acheive is the...
3
by: Widge | last post by:
I have made a spreadsheet that will calculate the distance from a set of addresses to a specified postcode in Excel. I'm looking to move this to Access so I can start thinking about hooking it up to...
3
by: D.Stone | last post by:
I'm trying to import an Excel spreadsheet into an existing Access table using Office 2003. Ultimately, the plan is to do it programmatically using TransferSpreadsheet, but to check that the file...
0
by: mcreary | last post by:
I HAVE A WORKBOOK WITH TWO SHEETS. I WANT TO SELECT A RANGE ON WORKSHEET "A" AND COMPARE (not necessarily the same item count) TO RANGE IN WORKSHEET "B", THEN RETURN RESULTS FROM WORKSHEET "B" TO...
1
by: scubasteve | last post by:
Looking up values from an Access table is simple. Simulating the 'Range Lookup' functionality from Excel's VLookup formula is a bit trickier. For those that aren't familiar with this, it allows...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
1
by: Kuttyrowdy | last post by:
I need to do the smilar vlookup (Excel function) in SQL command. Just explain to the below example Table 1 Store Type Region AA12 RGS AAA AA13 REM BBB AA14 RBK CCC Table 2
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.