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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,143,654
Messages
5,720,104
Members
422,266
Latest member
Mattyw

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
Top