Change sheet's codename via code

mond007

New Member
Joined
Oct 9, 2008
Messages
34
Hi
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
I have a workbook that has basic several worksheets but when I run a macro-report I am creating several dozen worksheet for each business unit. I delete these worksheets every time in order to create new statistics each time. The worksheet numbers ends up in the hundred.
<o:p></o:p>
I need to renumber the worksheet number (not the worksheet names). I know there is limit to the number of sheets of 255 but still it would be neat to renumber so that they are in ascending order. <o:p></o:p>
<o:p></o:p>
e.g.<o:p></o:p>
<o:p></o:p>
sheets1 (Tracker)<o:p></o:p>
sheets6 (Summary Report)<o:p></o:p>
sheets80 (Bus STOCK ORDER)<o:p></o:p>
sheets81 (Bus PURCHASING)<o:p></o:p>
sheets82 (Bus ACCOUNTS)<o:p></o:p>
sheets83 (Bus DEBT CONTROL)<o:p></o:p>
etc.
<o:p></o:p>
I would like them to be like :
<o:p></o:p>
sheets1 (Tracker)<o:p></o:p>
sheets2 (Summary Report)<o:p></o:p>
sheets3 (Bus STOCK ORDER)<o:p></o:p>
sheets4 (Bus PURCHASING)<o:p></o:p>
sheets5 (Bus ACCOUNTS)<o:p></o:p>
sheets6 (Bus DEBT CONTROL)<o:p></o:p>
etc.
<o:p></o:p>
Has anyone every done this. I have looked exhaustively and found many ways of reordering and renaming the worksheets(1).name etc but not the actually sheet number. I can also found sheets.index but hit a brick wall.
<o:p></o:p>
Has anyone every done this ?
<o:p></o:p>
Kind Regards Kuldip.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Re: renumber sheet number (not sheet names)

Welcome to the board.

You are referring to the sheet's codename. You can change it manually in the VB Editor using the Properties window. I don't know how to change it in code, but I'm sure someone else will if that's what you want!
 
Upvote 0
Re: renumber sheet number (not sheet names)

In code (but include some error checking!!)

Code:
ActiveWorkbook.VBProject.VBComponents(Sheets("Summary Report").CodeName) _
  .Properties("_CodeName") = "Sheet2"
 
Upvote 0
Re: renumber sheet number (not sheet names)

You would be better off, in my opinion, giving them a meaningful code name rather than sheet1, sheet2 etc. Also, be aware that changing the sheet's code name does not alter its index number.
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,180
Members
448,871
Latest member
hengshankouniuniu

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