VBA - Format multiple sheets at once

yykid

New Member
Joined
Aug 23, 2016
Messages
3
I have below codes to format multiple sheets at once, but it doesn't work. Anyone knows why? Thank you so much!

Sub Format_All()
Dim ws As Worksheet
For Each ws In Sheets(Array("1400", "1401", "1402", "1403", "1404", "1406", "1407", "1408", "1409", "1410", _
"1411", "1413", "1414", "1415", "1416", "1417", "1418", "1419", "1421", "1424", "1425"))
Sheets("1400").Activate
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Cut
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Columns("E:E").Select
Selection.Cut
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Columns("C:G").Select
Selection.EntireColumn.Hidden = True
Columns("K:M").Select
Selection.EntireColumn.Hidden = True
Columns("Q:Q").Select
Selection.EntireColumn.Hidden = True
Columns("S:S").Select
Selection.EntireColumn.Hidden = True
Columns("U:W").Select
Selection.EntireColumn.Hidden = True
Columns("X:X").Select
Selection.Delete Shift:=xlToLeft
Columns("Y:Y").Select
Selection.Replace What:="1", Replacement:="Yes", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="0", Replacement:="No", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Rows("1:1").RowHeight = 26.25
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("B:B").ColumnWidth = 7.86
Columns("H:H").ColumnWidth = 7.71
Columns("I:I").ColumnWidth = 9.29
Columns("J:J").ColumnWidth = 29
Columns("N:N").ColumnWidth = 20.57
Columns("O:O").ColumnWidth = 9.57
Columns("R:R").ColumnWidth = 10.14
Columns("T:T").ColumnWidth = 30.57
Columns("X:X").ColumnWidth = 6.57
Columns("Y:Y").ColumnWidth = 9.43

Next ws
Set ws = Nothing
Sheets("Worksheet").Select
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I have below codes to format multiple sheets at once, but it doesn't work. Anyone knows why? Thank you so much!

Sub Format_All()
Dim ws As Worksheet
For Each ws In Sheets(Array("1400", "1401", "1402", "1403", "1404", "1406", "1407", "1408", "1409", "1410", _
"1411", "1413", "1414", "1415", "1416", "1417", "1418", "1419", "1421", "1424", "1425"))
Sheets("1400").Activate
Columns("A:A").Select

[[-snip-]]

Next ws
Set ws = Nothing
Sheets("Worksheet").Select
End Sub
Change the hard coded "1400" to the loops incrementing variable ws (no quote marks).
 
Upvote 0

Forum statistics

Threads
1,216,728
Messages
6,132,368
Members
449,720
Latest member
NJOO7

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