Hello, my goal is to write a macro that will do a Vlookup on indefinite interval, for both data tested and range of Vlookup. When I run my Macro it selects the range, but it doesn't use it in Vlookup, so it returns me #Name error. Also I bet there is other ways to do that I'm trying to apply this to more complex problems, so I want to keep it as simple as possible.
Here is my Code so far:
Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+J
'
Dim rg As Range
Sheets("Sheet2").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Set rg = Selection
Sheets("Macro Sheet").Select
Range("B1").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet2!rg,2,FALSE)"
Range("B1").Select
Selection.Copy
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub
I was thinking maybe If I dim rg as something else but range it might work, Also I've tried just putting rg same problem, any help is appreciated.
Thank you
Bookmarks