stephicohu
New Member
- Joined
- Jan 27, 2023
- Messages
- 32
- Office Version
- 365
- Platform
- MacOS
Okay, what I want to do is I have make 29 rows with using the same colors on my conditional formatting. That means a lot of coding needs to be done! What I thought is I don't want to repeat those same code (in bold) for 29 times. I thought this would be great to have this as a function or subroutine. Each row will have unique format condition variables because they are individual values with different types and different operators specified in the add function of the format condition. Here is what I have right now:
VBA Code:
[
'define the range and conditions
Dim RngRow As Range
Dim OtherWalkCon1 As FormatCondition
Dim OtherWalkCon2 As FormatCondition
' delete all format conditions
Set RngRow = Range("B3 : F29")
RngRow.FormatConditions.Delete
'Other Walking Count 3 >=
Set RngRow = Range("B6 : F6")
Set OtherWalkCon1 = RngRow.FormatConditions.Add(xlCellValue, xlGreater, "=3")
Set OtherWalkCon2 = RngRow.FormatConditions.Add(xlCellValue, xlLess, "=3")
'define the color with bold for green condition
[B]OtherWalkCon1.Font.Bold = True
With OtherWalkCon1.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With[/B]
'define the color with bold for red condition
OtherWalkCon2.Font.Bold = True
[B]With OtherWalkCon2.Font
.Color = -16776961
.TintAndShade = 0
End With
With OtherWalkCon2.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 11841535
.TintAndShade = 0
.PatternTintAndShade = 0
End With[/B]
End Sub
]
The question I have is how do I make a generic variable for the formatconditions so I can make either a function or subroutine for the code that is bold? That way I don't have to copy and paste these lines for 29 times!
Thanks...
Stephanie