VBA vlookup code help

Excellis

New Member
Joined
Oct 30, 2012
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Can anyone offer any help with the following line of code:

ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet2!R[-60]C[-5]:R[454]C[-4],2,0)"

What I'm asking for it to do is a vlookup on the cell one to the left (=vlookup(RC[-1])
Move to sheet 2 and do a vlookup of the range A1:B454 (Sheet2!R[-60]C[-5]:R[454]C[-4]) and give me the value of column 2 (2,0)
The problem I'm having, because I recorded this as relative references, is it's moving the active cell -5 columns from the activecell column on sheet1 (which is fine, that column is fixed) but the code R[-60) is the difference between the activecell row on sheet1 and A1 on sheet two, and this number increases every time I run the code.

What I think I need is code to replace "Sheet2!R[-60]C[-5]:R[454]C[-4]" with VBA equivalent of "A1:B454". If that makes sense.

Thank you in anticipation.

Tom
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is this what you mean?
Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet2!R1C1:R454C2,2,0)"
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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