VLOOKUP provides 2042 error

jacko2401

New Member
Joined
Aug 24, 2011
Messages
35
I have 3 worksheets:
1. "Main": This is the output worksheet I will be working from
2. "Data": This has the underlying data worksheet
3. "Sheet2": This is seperate data that I want to check if it also appears in the "data" worksheet

The "Data" worksheet has column A with a list of unique names.
The "Sheet2" worksheet also has column A with a list of names where some of those names appear in the column A of Data worksheet.

As a starting point, I want to produce VBA code that will populate a column in the "Main" worksheet with all the names that appear in Sheet2 as well as Data. I've tried a looped VLOOKUP but it eventually comes back with a Error 2042 when a #N/A is produced.

Please can someone let me know if I am using the right statement that can be tweaked, the wrong stement or suggest a way tp make my coding more robust. Here is what I have so far:

'Find the last row of the sheet2 list of names so I know how many vlookup statements to make
Sheets("Sheet2").Select
Sheets("Sheet2").Range("A1").End(xlDown).Select
LastRow = ActiveCell.Row

'Selects the first cell in the main worksheet
Sheets("main").Select
Range("A1").Select

'completes a VLookup from sheet2 to search for data in data worksheet until reaches the last row of the data in Sheet2

Do
ActiveCell.FormulaR1C1 = "=VLOOKUP('Sheet2'!RC[1],Data!C[2]:C[9],1,FALSE)"
ActiveCell.Offset(1, 0).Select

Loop Until ActiveCell = ("A" & LastRow)
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,216,102
Messages
6,128,847
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top