H
harpreet.noni
Hi,
I am currently working on a simple requirement where I need to compare two columns (says Col C and F) in same worksheet with below requirements
1) If the value matches between two columns, the matching value is written to another column say D
2) For all matching, the rows/value (in column C and D) should be highlighted red and
3) For non-matching, the rows/values (in column C and D) should be highlighted green
More details.
The value in Column F is appended with timestamp (last 5 characters). Column C values are ok. While comparing, I want the Col F to ignore its last 5 characters and then compare values with Column C
Can anyone please assist here?
Work done till now.
This is what I could come up for now.
Sub compare_cols()
Dim c As Range
Dim d As Range
Set Report = Excel.Worksheets("Sheet1")
LRa = Range("C" & Rows.Count).End(xlUp).Row
LRb = Range("F" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To LRa
For Each c In Worksheets("Sheet1").Range("C2:C" & LRa)
For Each d In Worksheets("Sheet1").Range("F2:F" & LRb)
c.Interior.Color = vbRed
If (InStr(1, Left(d, Len(d) - 5), c, 1) > 0) Then
c.Interior.Color = vbGreen
Exit For
End If
Next
Next
Next i
Application.ScreenUpdating = True
End Sub
I am currently working on a simple requirement where I need to compare two columns (says Col C and F) in same worksheet with below requirements
1) If the value matches between two columns, the matching value is written to another column say D
2) For all matching, the rows/value (in column C and D) should be highlighted red and
3) For non-matching, the rows/values (in column C and D) should be highlighted green
More details.
The value in Column F is appended with timestamp (last 5 characters). Column C values are ok. While comparing, I want the Col F to ignore its last 5 characters and then compare values with Column C
Can anyone please assist here?
Work done till now.
This is what I could come up for now.
Sub compare_cols()
Dim c As Range
Dim d As Range
Set Report = Excel.Worksheets("Sheet1")
LRa = Range("C" & Rows.Count).End(xlUp).Row
LRb = Range("F" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To LRa
For Each c In Worksheets("Sheet1").Range("C2:C" & LRa)
For Each d In Worksheets("Sheet1").Range("F2:F" & LRb)
c.Interior.Color = vbRed
If (InStr(1, Left(d, Len(d) - 5), c, 1) > 0) Then
c.Interior.Color = vbGreen
Exit For
End If
Next
Next
Next i
Application.ScreenUpdating = True
End Sub