Set variable to Apply Macro to multiple worksheets

RosieRose

Board Regular
Joined
Jul 29, 2014
Messages
75
Hi there, I have written a macro for a specific workbook to apply to multiple worksheets, I have about 30 other workbooks to apply this to and the sheet numbers will be different in each work book. All sheets that need to be formatted contain the word "plot" in the name. How do I set a variable to activate any worksheets with "plot" in their name? here is the macro I would like to modify: Sub MacroThroughsheets()
Dim i As Integer
For i = 56 To 70
Sheets(i).Activate
ActiveSheet.Columns("A:A").ColumnWidth = 2
ActiveSheet.Columns("B:B").ColumnWidth = 7
ActiveSheet.Columns("C:C").ColumnWidth = 4
ActiveSheet.Columns("D:D").ColumnWidth = 7
ActiveSheet.Columns("E:E").ColumnWidth = 10
ActiveSheet.Columns("F:F").ColumnWidth = 9
ActiveSheet.Columns("G:G").ColumnWidth = 4
ActiveSheet.Columns("H:T").ColumnWidth = 8.14
ActiveSheet.Columns("U:U").ColumnWidth = 2
Rows("1:51").Select
Selection.RowHeight = 15
ActiveSheet.PageSetup.PrintArea = "$A$1:$U$51"
Next i
End Sub
Thank you!
 
I left the Dim i in by mistake but it will have absolutely no bearing on this not running.

Try opening a new workbook and just rename one of the three standard sheets as 'plot'
Then with that workbook active, run the code either full run or stepping through.

It should format that sheet of the three.
Then please report back.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
So what is potentially different about the workbooks you are trying to operate on?

As it is the code should have no issue with any sheets that are normally hidden.
It won't be bothered if there are no sheets that contain 'plot'.

It will error if the worksheet to be modified is protected?
Outside of that I'm at a loss to know.

Are you able to upload a typical file to say DropBox or some other share site?
Or PM me for an email address to send file.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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