Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50057

Excel 2010 VBA: Reference Formula To Another Workbook

$
0
0
Hello,

I am trying to reference a vlookup function to another workbook, the filename of the workbook will change overtime. I want to be able to make the formula dynamic so that it will always adjust to the file selected. Suggestions is very much appreciated.

Code:

ChDrive "C:\"
ChDir "C:\Users\30122458\Desktop"
Set lw2 = Nothing
tn = Application.GetOpenFilename(Filefilter:="Excel Files(*.xls),*.xls", Title:="Please select a file")
If tn = False Then
    an = MsgBox("You did not select a file. This process has been canceled", , "exit - hudas.iskaryote@gmail.com")
    Exit Sub
Else
    Workbooks.Open Filename:=tn
    Set lw2 = ActiveWorkbook
End If
ln1.Range("AC2").Formula = "=VLOOKUP(H2,'[All Active Listing up to 03-04-13.xls]03-04-13'!$1:$65536,10,FALSE)"

Thank you!

Viewing all articles
Browse latest Browse all 50057

Trending Articles