VLOOKUP To Previous Sheet

BrittKnee

Board Regular
Joined
Dec 4, 2017
Messages
82
Hi All. I am trying to code a dynamic VLOOKUP that references the sheet before my current sheet. The reason is that I am copying a new sheet with updated data to the workbook and then need to compare the old data (previous sheet) to the new in order to flag newly added records. I am currently using the below formula but am getting a #NAME? error. I'm assuming it has to do with the previous sheet reference. Any and all help is appreciated.

Code:
Range("T2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP([@[Position '#]],'" & ActiveSheet.Previous.Name & "'!D:S ,16,0)"
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try replacing this:
VBA Code:
ActiveSheet.Previous.Name
with this:
VBA Code:
Sheets(ActiveSheet.Index - 1).Name
 
Upvote 0
That worked except it added () around Column S in the range

Code:
=VLOOKUP([@[Position '#]],'Raw data_0912'!D:(S),16,0)
 
Upvote 0
You are are entering the formula in normal referencing, and not R1C1 referencing, do not use "FormulaR1C1".
You can also combine your code into one line (no need to select a range before working with it), i.e.
VBA Code:
Range("T2").Formula = "=VLOOKUP([@[Position '#]],'" & Sheets(ActiveSheet.Index - 1).Name & "'!D:S ,16,0)"
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,565
Messages
6,125,583
Members
449,237
Latest member
Chase S

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