satyagupta
New Member
- Joined
- Apr 20, 2020
- Messages
- 1
- Office Version
- 2016
- Platform
- Windows
I am new to VBA and tried to write code for color formatting with the help of internet. This code is split into various separate lines for each condition which I want to be merged into a single code using if and elseif but unable to do, please help. The following is the code.
Sub FillColor()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Cancelled"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 11780607
.TintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor1()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""File Closed"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 4962047
.TintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor2()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Foundation Done"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor3()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Got Location"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 10092543
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor4()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Location Pending"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13678776
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
End Sub
Sub FillColor()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Cancelled"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 11780607
.TintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor1()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""File Closed"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 4962047
.TintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor2()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Foundation Done"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor3()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Got Location"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 10092543
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub FillColor4()
With Sheets("RC-III GYM").Range("A:T").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Location Pending"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13678776
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End With
End Sub