Using cell name to open workbook

O

Orhan

Hi,

On H8 cell i have the value "data"
I managed to open the workbook named "data" using Range("H8")
Workbook.open function.

Set Wb2 = Workbooks.Open("c:\data\" & Range("H8") & ".xls")

How can I do the same thing in a vlookup formula?

ActiveCell.FormulaR1C1 =
"=VLOOKUP(RC[-12],data.xls!R2C1:R65008C38,3,FALSE)"

Thanks!
 
D

Dave Peterson

I'd use something like:

Dim DataRng as range
dim wb2 as workbook
set wb2 = workbooks.open(....)
with wb2.worksheets("someworksheetnamehere")
set datarng = .range("A2:AL65536")
end with

'make sure you're on the correct cell.

ActiveCell.FormulaR1C1 =
"=VLOOKUP(RC[-12]," _
& datarng.address(external:=true, ReferenceStyle:=xlR1C1) _
& ",3,FALSE)"




Hi,

On H8 cell i have the value "data"
I managed to open the workbook named "data" using Range("H8")
Workbook.open function.

Set Wb2 = Workbooks.Open("c:\data\" & Range("H8") & ".xls")

How can I do the same thing in a vlookup formula?

ActiveCell.FormulaR1C1 =
"=VLOOKUP(RC[-12],data.xls!R2C1:R65008C38,3,FALSE)"

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top