Using Sheet Name in combination with a named range [VBA/365/MAC]

LeighG

New Member
Joined
Feb 13, 2021
Messages
13
Office Version
  1. 365
Platform
  1. MacOS
Hi,

Office 365 / Mac OS

I have the following code which works perfectly. However I'd like to combine the Sheet Name (from the current workbook) in combination with the Named Range. I can't seem to get the syntax right.

VBA Code:
 Cells(1, 1).Value = ThisWorkbook.Names("Balance").RefersToRange(1, 1)

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try:
(Note that this to work "Balance" name scope should be only worksheet WorksheetName, not the workbook.)
(not tested in MacOS)
VBA Code:
Cells(1, 1).Value = Sheets("WorksheetName").Names("Balance").RefersToRange(1, 1)
 
Upvote 0
What does this mean "combine the Sheet Name (from the current workbook) in combination with the Named Range."

A sheet name is a string, a named range is a Range object. What does it mean to combine them?
 
Upvote 0
Try:
(Note that this to work "Balance" name scope should be only worksheet WorksheetName, not the workbook.)
(not tested in MacOS)
VBA Code:
Cells(1, 1).Value = Sheets("WorksheetName").Names("Balance").RefersToRange(1, 1)
That works an absolute treat! Thank you.

Re: The scope, I can't see that you can set that when naming a range in Excel Mac. That was why I specifically wanted to name the sheet
 
Upvote 0
What does this mean "combine the Sheet Name (from the current workbook) in combination with the Named Range."

A sheet name is a string, a named range is a Range object. What does it mean to combine them?
As I wanted to specifically name the sheet the Range was from. @eduzs nailed it.
 
Upvote 0
That works an absolute treat! Thank you.

Re: The scope, I can't see that you can set that when naming a range in Excel Mac. That was why I specifically wanted to name the sheet
Just for completeness, it seems that in Excel for Mac:
If a named Range exists in multiple sheets in the Workbook then Scope = Worksheet (and your solution works perfectly)
If a named Range only exists once in the Workbook then Scope = Workbook (and adding the sheet name causes an error)
 
Upvote 0
Use the "Name Manager" under "Formulas" tab to see the scope of each existing names.
In Windows Excel (don't know in MacOS version) you can see, edit (change scope, etc.), create named ranges with this menu.
If scope is ThisWorkbook then use ThisWorkbook.Names....
If Worksheet then Sheets("WorksheetName").Names... or by relative position Sheets(SheetNumber).Names...
 
Last edited:
Upvote 0
Use the "Name Manager" under "Formulas" tab to see the scope of each existing names.
In Windows Excel (don't know in MacOS version) you can see, edit (change scope, etc.), create named ranges with this menu.
If scope is ThisWorkbook then use ThisWorkbook.Names....
If Worksheet then Sheets("WorksheetName").Names... or by relative position Sheets(SheetNumber).Names...
Thanks. That's the thing....the scope option doesn't exist in the Mac Name Manager. So I think the 'default' scope is as per my previous post.
 
Upvote 0
To scope a name to the sheet level on a Mac, one the DefineName dialog enter the name qualified by sheet reference in the Name box

e.g. Sheet2!MyName will create a name MyName that is only valid on Sheet2.
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,453
Members
452,514
Latest member
cjkelly15

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