Sub apply_all_formatting()
' Freeze panes
' ------------
ActiveWindow.SplitColumn = 0
ActiveWindow.SplitRow = 1
ActiveWindow.FreezePanes = True
' Formatting
' ----------
Set wsSheet1 = Sheets("Sheet1")
With wsSheet1
' Create a Table with no TableStyle
.ListObjects.Add(xlSrcRange, .Range("A1").CurrentRegion, , xlYes).Name = "Summary"
.ListObjects("Summary").TableStyle = ""
' General settings (font, autofit and zoom)
.Activate
ActiveWindow.Zoom = 90
.Range("A1").CurrentRegion.Rows(1).Font.Bold = True
.Range("A1").CurrentRegion.Font.Name = "Calibri"
.Range("A1").CurrentRegion.Font.Size = "11"
.Range("A1").CurrentRegion.Columns.AutoFit
' Specific settings (header)
.Range("A1").CurrentRegion.Interior.Color = RGB(255, 255, 255)
.Range("A1").CurrentRegion.Rows(1).Interior.Color = RGB(166, 166, 166)
Union(Range("A1").CurrentRegion.Cells(, 6), Range("A1").CurrentRegion.Cells(, 11), Range("A1").CurrentRegion.Cells(, 16), _
Range("A1").CurrentRegion.Cells(, 21), Range("A1").CurrentRegion.Cells(, 26), Range("A1").CurrentRegion.Cells(, 31), _
Range("A1").CurrentRegion.Cells(, 36), Range("A1").CurrentRegion.Cells(, 41), Range("A1").CurrentRegion.Cells(, 46), _
Range("A1").CurrentRegion.Cells(, 51)).Interior.Color = RGB(216, 228, 188)
' Specific settings (column A + B - horizontal alignment)
.Range("A2:B" & Cells(Rows.Count, 1).End(xlUp).Row).HorizontalAlignment = xlRight
' Specific settings (column E - horizontal alignment)
.Range("E2:E" & Cells(Rows.Count, 5).End(xlUp).Row).HorizontalAlignment = xlLeft
'Clear the CurrentRegion of all groups
On Error Resume Next
.Range("A1").CurrentRegion.EntireColumn.Ungroup
On Error GoTo 0
' Group the columns between Time1, Time2, Time3, ...
.Range("B:B").Group
.Range("G:J").Group
.Range("L:O").Group
.Range("Q:T").Group
.Range("V:Y").Group
.Range("AA:AD").Group
.Range("AF:AI").Group
.Range("AK:AN").Group
.Range("AP:AS").Group
.Range("AU:AX").Group
.Range("AZ:BC").Group
' Set the group expansion to level 1
.Outline.ShowLevels ColumnLevels:=1
' Horizontally align the Range("F2:BC")
.Range("F2:BC" & Cells(Rows.Count, 5).End(xlUp).Row).HorizontalAlignment = xlCenter
.Range("A1").CurrentRegion.BorderAround (xlContinuous)
Union(Range("A1").CurrentRegion.Columns(6), Range("A1").CurrentRegion.Columns(11), Range("A1").CurrentRegion.Columns(16), _
Range("A1").CurrentRegion.Columns(21), Range("A1").CurrentRegion.Columns(26), Range("A1").CurrentRegion.Columns(31), _
Range("A1").CurrentRegion.Columns(36), Range("A1").CurrentRegion.Columns(41), Range("A1").CurrentRegion.Columns(46), _
Range("A1").CurrentRegion.Columns(51)).Borders(xlEdgeLeft).LineStyle = xlContinuous
End With
' Conditional Formatting
' ----------------------
lrowCount = ActiveSheet.Cells(Rows.Count, 5).End(xlUp).Row
With wsSheet1
'delete all conditional formatting
.Range("A2").CurrentRegion.FormatConditions.Delete
'#1 format RED - the cell if the Count number is odd.
With .Range("E2:E" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD($E2;2)=1"
.FormatConditions(1).Font.Color = 393372
.FormatConditions(1).Interior.Color = 13551615
End With
'#2 format YELLOW - the special entry/exit codes used
With .Range("F2:F" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($H2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("K2:K" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($M2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("P2:P" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($R2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("U2:U" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($W2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("Z2:Z" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($AB2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("AE2:AE" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($AG2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("AJ2:AJ" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($AL2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("AO2:AO" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($AQ2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("AT2:AT" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($AV2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
With .Range("AY2:AY" & lrowCount)
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN($BA2)>0"
.FormatConditions(1).Font.Color = 26012
.FormatConditions(1).Interior.Color = 10284031
End With
'#3 format GREY - the weekends (saturday or sunday)
With .Range("A1").CurrentRegion
.FormatConditions.Add Type:=xlExpression, Formula1:="=OR(WEEKDAY($A1)=7;WEEKDAY($A1)=1)"
.FormatConditions(12).Interior.Color = 14277081
End With
End With
End Sub
The result can be found in the attachment. Just click the format button!
Bookmarks