macro to change tab names

rhombus4

Well-known Member
Joined
May 26, 2010
Messages
586
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
IS it possible to run a Macro that will change the names of Tabs

i.e. if you have Sheet1-Sheet5 then In Sheet6 starting in A1-A5 the names of people.

When you ran the macro what was in cell A1 becomes the name of Sheet1 A2 becomes the name of Sheet2 and so on
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Per your example, you can use something like this
Code:
Sub NameShts()
Dim cl As Range
For Each cl In Sheet6.Range("$A$1:$A$5")
Sheets(cl.Row).Name = cl
Next cl
End Sub

lenze
 
Upvote 0
Per your example, you can use something like this
Code:
Sub NameShts()
Dim cl As Range
For Each cl In Sheet6.Range("$A$1:$A$5")
Sheets(cl.Row).Name = cl
Next cl
End Sub

lenze

Gives me a Run time error 1004 application - defined or object-defined error, then when I click debug highlights
Sheets(cl.Row).Name = cl
 
Upvote 0
Don't know!! It runs fine for me!!

lenze

Edit: Are all of your entries are valid sheet names? Perhaps an error trap may be needed!!
Code:
On Error Resume Next
 
Last edited:
Upvote 0
Don't know!! It runs fine for me!!

lenze

Edit: Are all of your entries are valid sheet names? Perhaps an error trap may be needed!!
Code:
On Error Resume Next

Opened New Excel Sheet and created sheets 1 - 6 and added macro but get following error

Get run time Error 424

Sub NameShts()
Dim cl As Range
For Each cl In Sheet6.Range("$A$1:$A$5")
Sheets(cl.Row).Name = cl
Next cl
On Error Resume Next
End Sub
 
Upvote 0
What are the names you want. I don't think they are valid!!. You placed the On Error statement in the wrong place
Code:
Sub NameShts()
Dim cl As Range
On Error Resume Next
For Each cl In Sheet6.Range("$A$1:$A$5")
Sheets(cl.Row).Name = cl
Next cl
End Sub
I've tested this several times and can not reproduce an error. It runs as expected!!
lenze<!-- / message -->
 
Upvote 0
What are the names you want. I don't think they are valid!!. You placed the On Error statement in the wrong place
Code:
Sub NameShts()
Dim cl As Range
On Error Resume Next
For Each cl In Sheet6.Range("$A$1:$A$5")
Sheets(cl.Row).Name = cl
Next cl
End Sub
I've tested this several times and can not reproduce an error. It runs as expected!!
lenze<!-- / message -->

Thanks. Not sure what went wrong I tried it again and i got an error then i ran it again and it worked.

So created a new book and did same thing and it works fine! :)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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