Running multiple macros together: What am I doing wrong?

lucie19

New Member
Joined
Apr 28, 2014
Messages
6
Hi All

I am currently trying to run a macro on individual sheets to change the name of the sheet to the value in A1 of the same sheet. The code I am using is

Sub myTabName()
ActiveSheet.Name = ActiveSheet.Range("A1")
End Sub

Which works perfectly on individual sheets.

However I want to set up a button to run this on the applicable sheets (31 in total) so I have created a run all macro.

Sub RunAll()
Call Sheet10.myTabName
Call Sheet11.myTabName
Call Sheet12.myTabName
Call Sheet13.myTabName
Call Sheet14.myTabName
Call Sheet15.myTabName
Call Sheet16.myTabName
Call Sheet17.myTabName
Call Sheet18.myTabName
Call Sheet19.myTabName
Call Sheet20.myTabName
Call Sheet21.myTabName
Call Sheet22.myTabName
Call Sheet23.myTabName
Call Sheet24.myTabName
Call Sheet25.myTabName
Call Sheet26.myTabName
Call Sheet27.myTabName
Call Sheet28.myTabName
Call Sheet29.myTabName
Call Sheet30.myTabName
Call Sheet31.myTabName
Call Sheet4.myTabName
Call Sheet46.myTabName
Call Sheet47.myTabName
Call Sheet49.myTabName
Call Sheet50.myTabName
Call Sheet51.myTabName
Call Sheet7.myTabName
Call Sheet8.myTabName
Call Sheet9.myTabName


End Sub

At this point it only runs on the sheet I am on and not other other sheets. I am really new to VBA and am learning as I go along so please forgive me if I'm being stupid!

The eventual outcome will be to attach the run all macro to a button to make it easy for all to use.

Any help or advice would be welcome. Thank you!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
Sub myTabNames()
  Dim ws As Worksheet
  For Each ws in ActiveWorkbook.Worksheets
    ws.Name = ws.Range("A1").Value
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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