FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,368
- Office Version
- 365
- 2016
- Platform
- Windows
In this code, I would like to loop through the cells (which I already have done), but how can I add in the looping of the different conditions? Fm1, then Fm2, then Fm3, etc.
The only thing that changes between the different constants is the $G5 and $H5
The only thing that changes between the different constants is the $G5 and $H5
VBA Code:
Sub SetCF()
Dim LastRow As Long: LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Dim LastColumn As Long: LastColumn = Cells(4, Columns.Count).End(xlToLeft).Column
Const Fm1$ = "=OR($G5<$F$1,$H5<$G$1)"
Const Fm2$ = "=OR($K5<$F$1,$L5<$G$1)"
Const Fm3$ = "=OR($O5<$F$1,$P5<$G$1)"
Const Fm4$ = "=OR($S5<$F$1,$T5<$G$1)"
Const Fm5$ = "=OR($W5<$F$1,$X5<$G$1)"
Const Fm6$ = "=OR($AA5<$F$1,$AB5<$G$1)"
Const Fm7$ = "=OR($AE5<$F$1,$AF5<$G$1)"
Const Fm8$ = "=Len(E5)>0"
Dim i As Long
For i = 5 To LastColumn Step 4
With Cells(5, i).Resize(62, 4)
With .FormatConditions
With .Add(Type:=xlExpression, Formula1:=Fm1)
.Borders.LineStyle = xlContinuous
.Interior.Color = RGB(244, 176, 132)
End With
End With
End With
Next i
End Sub