Sheet Names and Code Names

mavsmoney

New Member
Joined
Aug 27, 2015
Messages
2
I am trying to write a function that takes a cell's value, for example A1 = Sheet1, which is the codename of Sheet1, and return the worksheet name (which appears on the tab).

So in Microsoft Excel Objects you have Sheet1 (HelloWorld)

In cell A1 is the value Sheet1
In cell A2 I to write a function =GetSheetName(A1) and it returns the value HelloWorld.

I was able to do this in the reverse order (get Sheet1 from HelloWorld) with:

Public Function GetSheetName(rCell As String)
GetSheetName = rCell
GetSheetName = Worksheets(rCell).CodeName
End Function

But this does not work the other way around.

Thanks
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Not exactly a function, but I found a solution that will work in a subroutine.

Sub GetSheetName()
Dim Cell As Range
Dim WS As Worksheet
'Change Range in next line to the Range with Sheet1, Sheet2....'
For Each Cell In Worksheets("Example").Range("A1:A10")
For Each WS In ActiveWorkbook.Worksheets
If WS.CodeName = Cell.Value Then
Cell.Offset(0, 1).Value = WS.Name
End If
Next
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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