H
Heather O'Malley
I am trying to create a macro with a simple lookup function and copy. This
part is fine, however the file I will be looking up with be changing every
week - so I have added some variables.
I was thinking the spreadsheet directory and name could be typed into A10
and B10 of the sheet the data with be imported into "book2.xls" but am
having difficultly with related this to the formula...any help appreciated.
See attempt below:
Sub test()
Dim Importdir, Importfile
Importdir = Range("a10")
Importfile = Range("b10")
ChDir Importdir
Workbooks.Open Filename:=Importdir & Importfile,
UpdateLinks:=0
Windows("Book2.xls").Activate
Range("B1").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(RC[-1],[Targetfile]Sheet1!R1C1:R3C2,2,FALSE)"
Range("B1").Select
Selection.AutoFill Destination:=Range("B1:B3"), Type:=xlFillDefault
Range("B1:B3").Select
Windows(Importfile).Activate
ActiveWindow.Close
End Sub
part is fine, however the file I will be looking up with be changing every
week - so I have added some variables.
I was thinking the spreadsheet directory and name could be typed into A10
and B10 of the sheet the data with be imported into "book2.xls" but am
having difficultly with related this to the formula...any help appreciated.
See attempt below:
Sub test()
Dim Importdir, Importfile
Importdir = Range("a10")
Importfile = Range("b10")
ChDir Importdir
Workbooks.Open Filename:=Importdir & Importfile,
UpdateLinks:=0
Windows("Book2.xls").Activate
Range("B1").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(RC[-1],[Targetfile]Sheet1!R1C1:R3C2,2,FALSE)"
Range("B1").Select
Selection.AutoFill Destination:=Range("B1:B3"), Type:=xlFillDefault
Range("B1:B3").Select
Windows(Importfile).Activate
ActiveWindow.Close
End Sub