Good morning,
I am a complete newbie to Excel VBA but have been watching YouTube Videos and reading these forums to figure things out but I need your help as I am stuck...
I created the following macro and would like it to format all the worksheets in my spreadsheet (about 40 of them). However, the code below is formatting one of the worksheets and inserting 11 rows - not sure where the problem is.
The ideal goal would be to have this macro format all macros except my first three worksheets as they are my summary, instructions and initial macro pages.
Any suggestions? I would be happy to clarify the needs as well.
Thanks in advance!
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+L
'
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Columns("A:O").Select
Columns("A:O").EntireColumn.AutoFit
Columns("M:N").Select
Selection.ColumnWidth = 12.71
Rows("1:1").EntireRow.AutoFit
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1:O1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("F1").Select
ActiveCell.FormulaR1C1 = "Opportunity Report"
Range("H1").Select
ActiveCell.FormulaR1C1 = "=TODAY()+1"
Range("H1").Select
Columns("H:H").Select
Range("H2:H40").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""Due"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
Next ws
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
I am a complete newbie to Excel VBA but have been watching YouTube Videos and reading these forums to figure things out but I need your help as I am stuck...
I created the following macro and would like it to format all the worksheets in my spreadsheet (about 40 of them). However, the code below is formatting one of the worksheets and inserting 11 rows - not sure where the problem is.
The ideal goal would be to have this macro format all macros except my first three worksheets as they are my summary, instructions and initial macro pages.
Any suggestions? I would be happy to clarify the needs as well.
Thanks in advance!
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+Shift+L
'
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Columns("A:O").Select
Columns("A:O").EntireColumn.AutoFit
Columns("M:N").Select
Selection.ColumnWidth = 12.71
Rows("1:1").EntireRow.AutoFit
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1:O1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("F1").Select
ActiveCell.FormulaR1C1 = "Opportunity Report"
Range("H1").Select
ActiveCell.FormulaR1C1 = "=TODAY()+1"
Range("H1").Select
Columns("H:H").Select
Range("H2:H40").Activate
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""Due"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
Next ws
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub