I'm trying to write a macro in vba that will select a certain group of cells and set them as a range then perform a vlookup against that range all on the same sheet. My macro starts by jumping around the sheet to select the first range as rng1(usually the first 100 rows up to column R on the sheet). That part seems to work. But when I try to run a vlookup against rng1 the vlookup treats rng1 as cell "A1" only and not the first 100 rows up to column R. Here is an edited version of the code. Any help would be much appreciated.
Dim rng1 As Range
Dim r As Long
ActiveSheet.Range("I65536").Select
Selection.End(xlUp).Select
r = Selection.Row
Range("A1:R" & r).Select
Set rng1 = Selection
Range("e" & r).Offset(1, 0).Select
ActiveCell.Formula = "=vlookup(RC[-3],rng1,2,0)"
Dim rng1 As Range
Dim r As Long
ActiveSheet.Range("I65536").Select
Selection.End(xlUp).Select
r = Selection.Row
Range("A1:R" & r).Select
Set rng1 = Selection
Range("e" & r).Offset(1, 0).Select
ActiveCell.Formula = "=vlookup(RC[-3],rng1,2,0)"