Create Name with a value as a string

kienleong

New Member
Joined
Mar 17, 2010
Messages
13
I am looking to identify sheet templates by giving them a sheet level name.

If the sheet name contains a string, then I get "="string"" as the name value, not "string".

example code

Code:
Sub TestSheetName()
    
    Dim SheetType As String
    Dim Wksht As Worksheet
    
    Set Wksht = ActiveSheet
    SheetType = "SheetType1"
    
    Wksht.Names.Add Name:="SheetType", RefersTo:=SheetType
    MsgBox "The Sheet Name is " & Wksht.Names("SheetType").Value

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
It looks like it is naming the sheet correctly (if you view the Name Manager after running it). It just appears the Wksht.Names("SheetType").Value calculation returns the equal sign in VBA. You can get rid of that pretty easily:

Code:
MsgBox "The Sheet Name is " & Right(Wksht.Names("SheetType").Value, Len(Wksht.Names("SheetType").Value) - 1)
 
Upvote 0
So, looks like this might just be a quirk in Excel.

HTML:
Wksht.Names("SheetType")
Wksht.Names("SheetType").Value
Wksht.Names("SheetType").RefersTo

All return the same result that matches .RefersTo in name manager.

Your solution to clean it up is simple and effective.

Thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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