Referencing to named cell on different worksheet

Willem!

Board Regular
Joined
Mar 6, 2009
Messages
139
Hi, When I reference (in code) to a named cell on a different worksheet something goes wrong. When I use the following code, everything works fine:

Code:
Sub cmdButton_Click()
Dim dblNumber As Double
    dblNumber = Sheets("Birdie").Range("wbet").Value
    MsgBox dblNumber
End Sub

But when I use the following, I get an error:

Code:
Sub cmdButton_Click()
Dim dblNumber As Double
    dblNumber = Sheet20.Range("wbet").Value
    MsgBox dblNumber
End Sub

So when I replace 'Sheets("Birdie").Ran....' with 'Sheet20.Ran...' the error arises. I want to use the second line of code, because that's more flexible (users can alter the sheetname in that way).

What am I overseeing?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,

That's doens't work because your code suggests that "Sheet20" is the name of the sheet, which is not the case (it's name is Birdie, but it is Sheet20)
 
Upvote 0
onlya - I think that Sheet20 is the codename of the sheet called Birdie, so I don't think that would work?

Willem - your code works okay for me.
 
Upvote 0
:oops::oops::oops:

Oi!

I am a very silly man, I tried to reference to Sheet20 whereas the named call was located on Sheet15.

Thank you guys for your help!
thumbup.gif
 
Upvote 0

Forum statistics

Threads
1,203,047
Messages
6,053,197
Members
444,645
Latest member
mee siam

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