P
Pank
I have the following macro which I want executed for all worksheets within a
book.
I have tried it out and it only runs in the sheet that is selected, if I
choose another sheet and run it, it runs.
Can someone advise why it is not running against all sheets or what changes
are required to make it run against all sheets?
Sub Formatting()
‘The following hides columns A,C to E, G to M, and O to AL.
‘It then sets the column width for Columns B, F and N as well as the ‘row
height for row 1.
‘Lastly, columns B, F and N are selected and formatting done to ‘ensure that
they are not the Text within the columns is not ‘wrapped.
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
Columns("C:E").Select
Selection.EntireColumn.Hidden = True
Columns("G:M").Select
Selection.EntireColumn.Hidden = True
Columns("O:AL").Select
Selection.EntireColumn.Hidden = True
Columns("B:B").Select
Selection.ColumnWidth = 35
Columns("F:F").Select
Selection.ColumnWidth = 12
Columns("N:N").Select
Selection.ColumnWidth = 20
Rows("1:1").Select
Range("B1").Activate
Selection.RowHeight = 20
Columns("B:B").Select
With Selection
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("F:F").Select
With Selection
.HorizontalAlignment = xlLeft
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("N:N").Select
With Selection
.HorizontalAlignment = xlLeft
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Next wks
End Sub
Any assistance offered is appreciated.
book.
I have tried it out and it only runs in the sheet that is selected, if I
choose another sheet and run it, it runs.
Can someone advise why it is not running against all sheets or what changes
are required to make it run against all sheets?
Sub Formatting()
‘The following hides columns A,C to E, G to M, and O to AL.
‘It then sets the column width for Columns B, F and N as well as the ‘row
height for row 1.
‘Lastly, columns B, F and N are selected and formatting done to ‘ensure that
they are not the Text within the columns is not ‘wrapped.
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
Columns("C:E").Select
Selection.EntireColumn.Hidden = True
Columns("G:M").Select
Selection.EntireColumn.Hidden = True
Columns("O:AL").Select
Selection.EntireColumn.Hidden = True
Columns("B:B").Select
Selection.ColumnWidth = 35
Columns("F:F").Select
Selection.ColumnWidth = 12
Columns("N:N").Select
Selection.ColumnWidth = 20
Rows("1:1").Select
Range("B1").Activate
Selection.RowHeight = 20
Columns("B:B").Select
With Selection
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("F:F").Select
With Selection
.HorizontalAlignment = xlLeft
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("N:N").Select
With Selection
.HorizontalAlignment = xlLeft
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Next wks
End Sub
Any assistance offered is appreciated.