Changing Tab Names VBA

Tom98

New Member
Joined
Oct 26, 2020
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi,

If I wanted to go through each sheet and rename the tab names as the previous sheet plus 1, how would I go about doing this? Ie if I had sheet1, sheet2, sheet3 and sheet4, and then I were to delete sheet3 I would then like a macro to run to update the remaining sheets as sheet1, sheet2, sheet3. Any help with this would be great!

TIA
 
The problem is that if it starts at 1 and Sheets("Test_1") already exists, the macro will generate an error because you can't have two sheets with the same name.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The problem is that if it starts at 1 and Sheets("Test_1") already exists, the macro will generate an error because you can't have two sheets with the same name.
Okay, there wouldn't be a way of telling it to skip over the sheets that I don't want it to consider so to start it counting at 1 and going from there?

Sorry for the hassle.
 
Upvote 0
there wouldn't be a way of telling it to skip over the sheets that I don't want it to consider
Can you please explain in detail what you mean by this using a few examples?
 
Upvote 0
Can you please explain in detail what you mean by this using a few examples?
So currently I have:

|Front Cover | User guide | References | Button Sheet | Test_1 | Test_2 | Test_3 | Test_5 |

The solution you kindly provided produces:

|Front Cover | User guide | References | Button Sheet | Test_5 | Test_6 | Test_7 | Test_8 |

The solution I would ideally obtain:

|Front Cover | User guide | References | Button Sheet | Test_1 | Test_2 | Test_3 | Test_4 |

Is there a way of saying For each Worksheets in ThisWorkbook.Worksheets, if Sheets.Name<>"Test_*" then skip to next sheet? I don't know if this would work and don't know how to write it in vba exactly.

Cheers
 
Upvote 0
So currently I have:

|Front Cover | User guide | References | Button Sheet | Test_1 | Test_2 | Test_3 | Test_5 |

The solution you kindly provided produces:

|Front Cover | User guide | References | Button Sheet | Test_5 | Test_6 | Test_7 | Test_8 |

The solution I would ideally obtain:

|Front Cover | User guide | References | Button Sheet | Test_1 | Test_2 | Test_3 | Test_4 |

Is there a way of saying For each Worksheets in ThisWorkbook.Worksheets, if Sheets.Name<>"Test_*" then skip to next sheet? I don't know if this would work and don't know how to write it in vba exactly.

Cheers
I believe that changing it to
Sub ReNameSheets()
Application.ScreenUpdating = False
Dim x As Long
For x = ActiveSheet.Index + 1 To Sheets.Count
Sheets(x).Name = "Test_" & x - 4
Next x
Application.ScreenUpdating = True
End Sub

does the job.

Thanks for all your help :)
 
Upvote 0
You are very welcome and well done. :)
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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