Hi guys,
Here's hoping somebody can assist in helping me modify an existing code shown below.
The current code adds some conditional formatting to an activesheet and is working great.
I need to add another bit of conditional formatting which is =AND(E22=B22,G22<d22 1.2)<="" font="">
The code needs to loop through the sheet and be added to every third column until the last column as the existing doc does
This is existing code that is working great.
This is code I have tried to modify without much success
Many thanks for any help or advice given
Question also posted https://www.excelforum.com/excel-pr...and-loop-through-activesheet.html#post4633636
but unfortunately had no response.</d22>
Here's hoping somebody can assist in helping me modify an existing code shown below.
The current code adds some conditional formatting to an activesheet and is working great.
I need to add another bit of conditional formatting which is =AND(E22=B22,G22<d22 1.2)<="" font="">
The code needs to loop through the sheet and be added to every third column until the last column as the existing doc does
This is existing code that is working great.
Code:
[COLOR=#333333]Sub Add_Conditional_Formatting_2Letters()[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"> Dim LastCol As Long
Dim NextCol As Long
Dim rg As Range
Dim s1 As String
Dim s2 As String
With ActiveSheet
LastCol = .Cells(22, Columns.Count).End(xlToLeft).Column
For NextCol = 7 To LastCol Step 3
Set rg = .Range(Cells(22, NextCol), Cells(80, NextCol))
s1 = Replace(rg.Offset(, -2).Address, "$", "")
s2 = Replace(rg.Offset(, -5).Address, "$", "")
With rg _
.FormatConditions.Add(Type:=xlExpression, _
Formula1:="=" & s1 & "<>" & s2)
.Interior.Color = RGB(0, 204, 205) 'Blue
.Font.Color = RGB(0, 0, 0) 'Black
End With
Next
End With </code>[COLOR=#333333]End Sub[/COLOR]
This is code I have tried to modify without much success
Code:
[COLOR=#333333]Sub Add_Conditional_Formatting_2Lettersmodded()[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;"> Dim LastCol As Long
Dim NextCol As Long
Dim rg As Range
Dim s1 As String
Dim s2 As String
Dim s3 As String 'new line added
Dim s4 As String 'new line added
With ActiveSheet
LastCol = .Cells(22, Columns.Count).End(xlToLeft).Column
For NextCol = 7 To LastCol Step 3
Set rg = .Range(Cells(22, NextCol), Cells(80, NextCol))
s1 = Replace(rg.Offset(, -2).Address, "$", "")
s2 = Replace(rg.Offset(, -5).Address, "$", "")
s3 = Replace(rg.Offset(, 0).Address, "$", "") 'new line added
s4 = Replace(rg.Offset(, -3).Address, "$", "") 'new line added
With rg _
.FormatConditions.Add(Type:=xlExpression, _
Formula1:="=" & s1 & "<>" & s2)
.Interior.Color = RGB(0, 204, 205) 'Blue
.Font.Color = RGB(0, 0, 0) 'Black
End With
With rg _
.FormatConditions.Add(Type:=xlExpression, _
Formula1:="=" & "AND" & "(" & s1 & "=" & s2 & "," & s3 & "<" & s4 & "/" & "1.2") '=AND(E22=B22,G22<d22 1.2
.Interior.Color = RGB(255, 0, 0) 'Blue
.Font.Color = RGB(255, 255, 255) 'Black
End With
Next
End With </d22></code>[COLOR=#333333]End Sub[/COLOR]
Many thanks for any help or advice given
Question also posted https://www.excelforum.com/excel-pr...and-loop-through-activesheet.html#post4633636
but unfortunately had no response.</d22>
Last edited: