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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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