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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,043
Messages
6,122,825
Members
449,096
Latest member
Erald

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