I have a macro that allows the user to choose a workbook from a folder and assigns the workbook a name and the name is WBName. The reason is because this workbooks name always changes. Here is the part of the code that does opens the selected workbook:
WBName = fd.SelectedItems(1)
Workbooks.Open (WBName)
WBName is open but the active workbook is Sales Report.xls, this happens on down in the code a bit.
I want to do a VLOOKUP to bring data into the Sales Report from WBName via my macro. If typed into a cell here is what it would look like:
=VLOOKUP(D4,CHOOSE({2,1},'[Sales 03-20-13.xls]Sheet1'!$D$3:$D$200,[Sales 03-20-13.xls]Sheet1'!$G$3:$G$200),2,0)
In my VBA code Sales 03-20-13.xls is given the name WBName.
How would I write the VLOOKUP in my VBA code?
I know it is not going to be:
Range("J3").Formula = "=VLOOKUP(D4,CHOOSE({2,1},WBName.Sheet1.Range("$D$3:$D$" & LastRow),WBName.Sheet1.Range("$G$3:$G$" & LastRow),2,0)"
I've tried several variations and have failed.
Thanks!