vba vlookup & named range

Joe Z

New Member
Joined
Mar 9, 2006
Messages
44
I am having difficulty using vlookup in vba using FormulaR1C1. I am tring to lookup a value from a table using the table O_Rng located in a different sheet. Here is what I have:
HTML:
Dim O_Rng as range

set O_Rng = Range("org_tbl!$A$2:$H$59")

sheets("Sheet3").cells(2,9).select
activecell.offset(4,0).FormulaR1C1= "=vlookup(RC[-7],org_tbl!O_Rng,2,false)

I get #Name error.
I have tried changing the lookup table value to
HTML:
activecell.offset(4,0).formulaR1C1= 
"=vlookup(RC[-7],Worksheets(""org_tbl"").range(""$A$2:$H$59""),2,false)
with no luck, yet I can use
HTML:
Activecell.offset(4,0) = application.worksheetfunction _
.vlookup(Activecell.offset(4,-7),worksheets("org_tbl").range("$A$2:$H$59"),2,false)
and it gives me the correct result.

Any suggestions, thanks in advance!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Joe

It's not particularly clear what you want to do but perhaps this might work.
Code:
Dim O_Rng As Range
Set O_Rng = Range("org_tbl!$A$2:$H$59")
Sheets("Sheet3").Cells(2, 9).Offset(4, 0).FormulaR1C1 = "=vlookup(RC[-7],org_tbl!" & O_Rng.Address(ReferenceStyle:=xlR1C1) & ",2,false)"
PS Why are you mixing up A1 and R1C1 notation? Wouldn't it just become confusing.:eek:
 
Upvote 0
Joe

It's not particularly clear what you want to do but perhaps this might work.
Code:
Dim O_Rng As Range
Set O_Rng = Range("org_tbl!$A$2:$H$59")
Sheets("Sheet3").Cells(2, 9).Offset(4, 0).FormulaR1C1 = "=vlookup(RC[-7],org_tbl!" & O_Rng.Address(ReferenceStyle:=xlR1C1) & ",2,false)"
PS Why are you mixing up A1 and R1C1 notation? Wouldn't it just become confusing.:eek:
Thank you! You were right on. My problem was I did not realize that I needed to include the .address to the named range. I am very new to vba, hence the mixing od A1 R1C1 notation. It was the result of trying numerous scenarios and getting them all meshed together. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top