Macro to Name Sheets by Tab Order

WednesdayC

Board Regular
Joined
Nov 7, 2010
Messages
201
Office Version
  1. 2016
Platform
  1. MacOS
Hi All

Is there a macro to name Worksheets by tab order?

If, for instance, I named the Worksheets Test 1, Test 2, Test 3 up to Test 52, I may need to move the order of Sheets, so for instance, if I moved Test 3 to Test 2 position, I would then like to be able to invoke a macro to rename all the sheets in sequential tabbed order.

Any help would be appreciated.

Regards
Wednesday






 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
No there isn't, but I dare say one could be written... :)

Try this on a copy of your workbook:-
Code:
[FONT=Fixedsys]Option Explicit[/FONT]
 
[FONT=Fixedsys]Sub RenameSheets()[/FONT]
 
[FONT=Fixedsys]Const sRoot As String = "[COLOR=red]Test [/COLOR]"[/FONT]
 
[FONT=Fixedsys]Dim ws As Worksheet[/FONT]
[FONT=Fixedsys]Dim iSeq As Integer[/FONT]
 
[FONT=Fixedsys]iSeq = 0[/FONT]
 
[FONT=Fixedsys]For Each ws In ThisWorkbook.Worksheets[/FONT]
[FONT=Fixedsys]   iSeq = iSeq + 1[/FONT]
[FONT=Fixedsys]   ws.Name = CStr(iSeq)[/FONT]
[FONT=Fixedsys]Next ws[/FONT]
 
[FONT=Fixedsys]For Each ws In ThisWorkbook.Worksheets[/FONT]
[FONT=Fixedsys]   ws.Name = sRoot & ws.Name[/FONT]
[FONT=Fixedsys]Next ws[/FONT]
 
[FONT=Fixedsys]End Sub[/FONT]
Set the value of sRoot as required.

This doesn't change the sheet's code name though.
 
Last edited:
Upvote 0
Hi Ruddles

Thank you very much once again (you helped me yesterday).

It works!!!!

Oh to be as smart as you.

Regards

Wednesday
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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