Need code to get the worksheet number not name

earldunning

Active Member
Joined
Nov 9, 2006
Messages
263
I know how to get and use the worksheet names but is there a way to get the sheet number?


For example, a sheet might be named "raw data" but the underlying object name is really "sheet4" which is used in VB Project/objects.

How can I get the "4" ?

I am trying to attach some code within a sheet so that I can use it when I copy the sheet and create a new workbook.
see my other link regarding macros creating macros -
http://www.mrexcel.com/forum/showthread.php?t=380307
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Use the CodeName property of the worksheet. As in

Code:
Sub shtname()
Dim wsht As Worksheet

    For Each wsht In Worksheets
        MsgBox wsht.CodeName
    Next wsht
    
End Sub
 
Upvote 0
I take that back..its not giving me the total number of sheets.
But it definitely isnt giving me the sheet number.
I get the same answer for multiple sheets in the same workbook.
When I right click the tab and view code, its definitely not the sheet number.
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,337
Members
448,568
Latest member
Honeymonster123

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