Rename Worksheets Using "Master" Worksheet

onlyonekj

New Member
Joined
Jun 27, 2019
Messages
18
Hello,

I need to change the name of the spreadsheets in the Workbook using a "Master" list created in the same Workbook. I tried to use the VBA below but got a 400 error code. I appreciate any assistance...I feel it is something simple I just cannot figure it out. I was going to attach the spreadsheet but I don't have permissions to do so. Thanks.

Worksheets Currently Named: .73, .74, .75, .76, .77, through .200
Need to Change Worksheet Names to: .74, .75, .76, .77, through .200

Sub ChangeTabNames()
Dim rng As Range, i As Integer
Application.ScreenUpdating = False
For Each rng In Worksheets("Master").Range("A:A201")
i = i + 1: Sheets("." + i).Name = rng.Value
Next rng
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Firstly, just to understand the task....
Existing sheet name .73 will become .74 , existing .74 will become .75. etc ??
So sequential numbers 74 :200
What becomes of old .200?

You have these 'new' names in Master column A ?

Clarify the above and you will get assistance.


Comments on your code.
Application.ScreenUpdating = False. Always ensure you reinstate at the end of code with Application.ScreenUpdating = True

Your specified range needs a starting row eg. Range("A1:201")
Your variable i starts at 0, ???
If you are going to rename and use similar names to existing then you may need to work backwards through the sheets or use a dummy in order to avoid any duplicate name error.
 
Upvote 0
If you have the names you want to use for your worksheets listed in column A then you can just use a For loop to rename the existing sheets, provided they are in the same order as the list. Say you want to start with listed on row 6 of Column A. It would be sheet 5 in the workbook.
Code:
Sub t()
For i = 5 To 199    Sheets(i).Name = Sheets("Master").Range("A" & i + 1).Value
Next
End Sub
But like Snakehips pointed outs, it is not clear what you have in column A or if you want to change all of your sheet names or just a few.
 
Last edited:
Upvote 0
@onlyonekj I assume that you have data to preserve in these sheets otherwise you would just delete '.73' and add a new last sheet?

Anyway, try...

Code:
Sub ookj()

'Assumes all sheets bar Master are to be renamed as per a full listing in column A
'Because of the potential for duplicate name error in renaming .73 as .74
'Start with the last sheet and work backwards


Application.ScreenUpdating = False
For i = Sheets.Count To 2 Step -1
Sheets(i).Name = Sheets("Master").Range("A" & i - 1).Value
Next
Application.ScreenUpdating = True

Hope that helps.
 
Last edited:
Upvote 0
Solution
Snakehips...thank you so much. Yes, I did want to preserve my that data on the spreadsheets. It worked like a charm...I am so excited right now...:) I really appreciate it.
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,664
Members
452,992
Latest member
TokugawaIesuma

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