Run Macro on Each Sheet / Next 29 sheets

Joined
May 24, 2007
Messages
26
I have a tab that lists my desired sheet names in Column A, rows 1-29. (There are exactly 29 rows already created).

HTML:
Dim i As Long
For i = 1 To ActiveWorkbook.Sheets.Count
On Error Resume Next
ActiveWorkbook.Sheets(i).Name = ActiveSheet.Cells(i, "A").Text
Next i

I've realized now that I need to run another macro within each of these new sheets (and only these new sheets) to insert some formulas, etc. Where can I put the macro information so it works on every sheet?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
It looks like any action you want to happen on each sheet would need to be directly above the "Next i" line, so that it is executed after the sheet is selected, but before you move to the next one. Hope this helps.
 
Upvote 0
One way:
Code:
Sub KISS()
    Dim i           As Long
    Dim wks         As Worksheet
    
    For i = 1 To ActiveWorkbook.Sheets.Count
        Set wks = ActiveWorkbook.Sheets(i)
        With wks
            .Name = ActiveSheet.Cells(i, "A").Text
            
            ' carry on; e.g.,
            .Range("A1").Value = "Bob"
            '...
        End With
    Next i
End Sub
 
Upvote 0
You're welcome, glad it helped.
 
Upvote 0

Forum statistics

Threads
1,216,118
Messages
6,128,939
Members
449,480
Latest member
yesitisasport

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