conditional formatting

satyagupta

New Member
Joined
Apr 20, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. 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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi & welcome to MrExcel.
You can put them together like
VBA Code:
Sub satyagupta()
   With Sheets("RC-III GYM")
      With Intersect(.UsedRange, .Range("A:T"))
         .FormatConditions.Delete
         .FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Cancelled"""
         .FormatConditions(.FormatConditions.Count).SetFirstPriority
         With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 11780607
            .TintAndShade = 0
         End With
         .FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""File Closed"""
         .FormatConditions(.FormatConditions.Count).SetFirstPriority
         With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 4962047
            .TintAndShade = 0
         End With
         .FormatConditions.Add Type:=xlExpression, Formula1:="=$Q1=""Foundation Done"""
         .FormatConditions(.FormatConditions.Count).SetFirstPriority
         With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent6
            .TintAndShade = 0.599993896298105
            .TintAndShade = 0
         End With
      End With
   End With
End Sub
You just need to add the last two rules in the same way
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top