This code simply formats my sheet but it takes forever and a day to finish the job....is there a more effective way to write this?
(a lot of it has been taken from recording macros and using that code)
Sub FormattingGlobal()
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet.Range("A1:AI300")
.FormatConditions.Delete
End With
With Range("A17:K190")
With .Font
.Name = "Arial"
.Size = 9
.Superscript = False
.Subscript = False
End With
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
End With
With Range("A193:E250")
With .Font
.Name = "Arial"
.Size = 9
.Superscript = False
.Subscript = False
End With
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
End With
ActiveWindow.Zoom = 80
ActiveWindow.SmallScroll Down:=-250
For Each x In Range("Account,AccountAPRP,Comment")
x.Value = Application.Proper(x.Value)
Next
For Each x In Range("Subnr,SubnrAPRP,UW")
x.Value = UCase(x.Value)
Next
Range("A18:F190,I18:K190").NumberFormat = "General"
With Range("M17:N190, G17:H190, D193:D250")
Selection.NumberFormat = "[$$-409]#,##0"
.HorizontalAlignment = xlRight
With Range("Subnr")
.FormatConditions.Add Type:=xlExpression, Formula1:="=AND(F17=""Renewal"",A17="""")"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
End With
With Range("RenDate")
.FormatConditions.Add Type:=xlExpression, Formula1:="=AND(L17="""",A17<>"""")"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
End With
With Range("Source")
.FormatConditions.Add Type:=xlTextString, String:="EU Corporate", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10092288
.TintAndShade = 0
End With
End With
With Range("Chklist")
.FormatConditions.Add Type:=xlExpression, Formula1:="=AND(F17=""Renewal"",O17=""N"")"
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
End With
With Range("Likelihood")
.FormatConditions.Add Type:=xlTextString, String:="Amber", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlTextString, String:="Green", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13434777
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlTextString, String:="Red", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 8420607
.TintAndShade = 0
End With
End With
With Range("Source")
.FormatConditions.Add Type:=xlTextString, String:="Company", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14734864
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlTextString, String:="Syndicate", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlTextString, String:="Bermuda", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.399945066682943
End With
End With
With Range("Account")
.FormatConditions.Add Type:=xlExpression, Formula1:="=J17=""Red"""
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = False
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 8420607
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlExpression, Formula1:="=J17=""Amber"""
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = False
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlExpression, Formula1:="=J17=""Green"""
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = False
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13434777
.TintAndShade = 0
End With
End With
With Range("SourceAPRP")
.FormatConditions.Add Type:=xlTextString, String:="EU Corporate", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10092288
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlTextString, String:="Syndicate", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
.FormatConditions.Add Type:=xlTextString, String:="Company", TextOperator:=xlContains
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(1).StopIfTrue = True
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 14734864
.TintAndShade = 0
End With
Range("A1").Select
Selection.NumberFormat = "mmm-yy"
End With
Range("M16").Select
Application.ScreenUpdating = True
Application.EnableEvents = True
Columns.AutoFit
Range("A15").Select
End With
End Sub
Bookmarks