macro to run on mutiple workseets

Eric Kelcher

Board Regular
Joined
May 11, 2006
Messages
130
I have a macro that I would like to run on multiple worksheets within a workbook, The names of the worksheets is not consistent nor is there always the same number of worksheets. Is there a way to make this happen?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The script I have written reformats the data into format that is printable then prints the page. I currently have to run macro on each page which it does correctly.

Here is the actual script, I use to have a recommended add-on that I cannot recall what it was called for creating a file for bringing macros into the BBS that I have lost with the new computer upgrade. ???

Columns("F:F").Select
Selection.ColumnWidth = 45
With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveWindow.LargeScroll ToRight:=-1
Columns("E:E").Select
Selection.ColumnWidth = 5
Columns("D:D").Select
Selection.ColumnWidth = 20
Columns("C:C").Select
Selection.ColumnWidth = 5
Columns("B:B").Select
Selection.ColumnWidth = 5
Columns("A:A").Select
Selection.ColumnWidth = 5
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
 
Last edited:
Upvote 0
Eric

Not sure how to handle the ExecuteExcel4Macro but this will run the rest of the code on all the sheets in the activeworkbook.
Code:
For Each ws In ActiveWorkbook.Sheets

    With ws
        With .Columns("F:F")
            .ColumnWidth = 45
            .VerticalAlignment = xlBottom
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        .Columns("E:E").ColumnWidth = 5
        .Columns("D:D").ColumnWidth = 20
        .Columns("C:C").ColumnWidth = 5
        .Columns("B:B").ColumnWidth = 5
        .Columns("A:A").ColumnWidth = 5
        
'        ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
        
    End With
    
Next ws
 
Upvote 0
Thank you that did it, I moved the print function to the end as a print entire workbook function rather than printing each page after formatting.

IE replaced
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
with
ActiveWorkbook.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
after the Next WS command
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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