aliceinthewonderland
New Member
- Joined
- Sep 21, 2021
- Messages
- 3
- Office Version
- 2016
- Platform
- Windows
Hi guys, I am trying to build a Macro that will do the following:
Select each row and check it against all rest of the rows, based on a criteria / formula. Once criteria is fulfilled, the selected row will be colored in yellow The row causing the selected row to be highlighted will be colored in red.
I want to modify my code so that for the following loop, it will skip those row that are already highlighted. I have my thought of how to do it just that I don't know the code... Can anyone offer some insights / help? Thank you and I appreciate it!
My solution: build an empty list, loop rows that are not in the list. whenever a row is highlighted, it will go into the list.
My current code are like this:
Sub Highlight()
Dim i As Long
Dim m As Long
Dim was As Worksheet
Set ws = ActiveSheet
With ws
For m = .Cells(.rows.Count, 1).End(xlUp).Row To 2 Step -1
For i = .Cells (.Rows.Count, 1).End(xlUp).Row To 2 Step -1
if .Cells (i,1).Value = .Cells (m,1).Value And .Cells (i,2).Value <> .Cells (m,2).
Range(Cells(i,"A"), Cells(i, "G")).Interior.color = vbRed
Range(Cells(m,"A"), Cells(m, "G")).Interior.color = vbYellow
Next i
Next m
End with
End sub
Select each row and check it against all rest of the rows, based on a criteria / formula. Once criteria is fulfilled, the selected row will be colored in yellow The row causing the selected row to be highlighted will be colored in red.
I want to modify my code so that for the following loop, it will skip those row that are already highlighted. I have my thought of how to do it just that I don't know the code... Can anyone offer some insights / help? Thank you and I appreciate it!
My solution: build an empty list, loop rows that are not in the list. whenever a row is highlighted, it will go into the list.
My current code are like this:
Sub Highlight()
Dim i As Long
Dim m As Long
Dim was As Worksheet
Set ws = ActiveSheet
With ws
For m = .Cells(.rows.Count, 1).End(xlUp).Row To 2 Step -1
For i = .Cells (.Rows.Count, 1).End(xlUp).Row To 2 Step -1
if .Cells (i,1).Value = .Cells (m,1).Value And .Cells (i,2).Value <> .Cells (m,2).
Range(Cells(i,"A"), Cells(i, "G")).Interior.color = vbRed
Range(Cells(m,"A"), Cells(m, "G")).Interior.color = vbYellow
Next i
Next m
End with
End sub