Hi, I'm struggling to find and highlight more than two duplicates in a rows, based on two columns, i.e I have a set number in col Y and a system defect in col AE and I have to highlight the same two data down across the rows. I actually can't exclude the columns between Y and AE, so it's highlighting all between them Can you advice, please?
That's my code below:
Dim lngMyCol As Long, _
lngEndRow As Long
Dim strMyCol As String
Dim lngStartRow As Long
Dim rngCell As Range
Application.ScreenUpdating = False
lngMyCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
lngEndRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
strMyCol = Left(Cells(1, lngMyCol).Address(True, False), Application.WorksheetFunction.Search("$", Cells(1, lngMyCol).Address(True, False)) - 1)
lngStartRow = 3 'Starting row number. Change to suit.
With Columns(strMyCol)
With Range(strMyCol & lngStartRow & ":" & strMyCol & lngEndRow)
.Formula = "=Y2&AE2"
.Value = .Value
End With
End With
For Each rngCell In Range(strMyCol & lngStartRow & ":" & strMyCol & lngEndRow)
If Evaluate("Countif(" & strMyCol & lngStartRow & ":" & strMyCol & lngEndRow & "," & rngCell.Address & ")") > 2 Then
Range("Y" & rngCell.Row & ":AE" & rngCell.Row).Interior.Color = RGB(0, 255, 0) 'Highlights dups in green. Change to suit.
End If
Next rngCell
Columns(strMyCol).Delete 'Delete helper column containing primary key
Application.ScreenUpdating = True
MsgBox "Duplicate rows have now been highlighted"
End Sub
Thank you in advance!
That's my code below:
Dim lngMyCol As Long, _
lngEndRow As Long
Dim strMyCol As String
Dim lngStartRow As Long
Dim rngCell As Range
Application.ScreenUpdating = False
lngMyCol = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
lngEndRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
strMyCol = Left(Cells(1, lngMyCol).Address(True, False), Application.WorksheetFunction.Search("$", Cells(1, lngMyCol).Address(True, False)) - 1)
lngStartRow = 3 'Starting row number. Change to suit.
With Columns(strMyCol)
With Range(strMyCol & lngStartRow & ":" & strMyCol & lngEndRow)
.Formula = "=Y2&AE2"
.Value = .Value
End With
End With
For Each rngCell In Range(strMyCol & lngStartRow & ":" & strMyCol & lngEndRow)
If Evaluate("Countif(" & strMyCol & lngStartRow & ":" & strMyCol & lngEndRow & "," & rngCell.Address & ")") > 2 Then
Range("Y" & rngCell.Row & ":AE" & rngCell.Row).Interior.Color = RGB(0, 255, 0) 'Highlights dups in green. Change to suit.
End If
Next rngCell
Columns(strMyCol).Delete 'Delete helper column containing primary key
Application.ScreenUpdating = True
MsgBox "Duplicate rows have now been highlighted"
End Sub
Thank you in advance!