Okay, I am kind of new to Excel (35 years making music videos, 6 months doing this) but I think I'm headed in the right direction. However, this is driving me nuts. What I need this to do is compare the data on on Sheet1 with the remaining sheets and then mark the duplicates if, and only if, they match all three columns (K, L & O) in Sheet1. I do not need Sheet1 to have any highlights at all. As you can tell, there will be quite a few sheets once this gets going and that I am nowhere near where I need to be.
I am attaching a sample data sheet so no one has to make one. Dupe Test.xlsx
As a bonus if there is some way to just have it check the work book without having to name tabs, since some work books will have prenamed tabs, that would be great too.
Thanks in advance for your help.
I am attaching a sample data sheet so no one has to make one. Dupe Test.xlsx
As a bonus if there is some way to just have it check the work book without having to name tabs, since some work books will have prenamed tabs, that would be great too.
Thanks in advance for your help.
Code:
Sub HighlightDuplicatesMacro()
Const shtNames As String = "Sheet1, Sheet2, Sheet3, Sheet4, Sheet5, Sheet6, Sheet7, Sheet8, Sheet9, Sheet10, Sheet11, Sheet12, Sheet13, Sheet14, Sheet15, Sheet16, Sheet17, Sheet18, Sheet19, Sheet20, Sheet21, Sheet22, Sheet23, Sheet24, Sheet25, Sheet26, Sheet27, Sheet28, Sheet29, Sheet30, Sheet31, Sheet32, Sheet33, Sheet34, Sheet35, Sheet36, Sheet37, Sheet38, Sheet39, Sheet40, Sheet41, Sheet42, Sheet43, Sheet44, Sheet45, Sheet46, Sheet47, Sheet48, Sheet49, Sheet50, Sheet51, Sheet52, Sheet53, Sheet54, Sheet55, Sheet56, Sheet57, heet58, Sheet59, Sheet60, Sheet61, Sheet62, Sheet63, Sheet64, Sheet65, Sheet66, Sheet67, Sheet68, Sheet69, Sheet70, Sheet71, Sheet72, Sheet73, Sheet74, Sheet75, Sheet76, Sheet77, Sheet78, Sheet79, Sheet80, Sheet81, Sheet82, Sheet83, Sheet84, Sheet85, Sheet86, Sheet87, Sheet88, Sheet89, Sheet90, Sheet91, Sheet92, Sheet93, Sheet94, Sheet95, Sheet96, Sheet97, Sheet98, Sheet99, Sheet100"
Const DupCells As String = "K2:K100, L2:L100, O2:O100"
Dim ws() As String: ws = Split(shtNames, ",")
Dim i As Integer, j As Integer
Dim CheckCell As Range, rngFound As Range
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Reset all cells in order to: '
' Allow new duplicates to be found '
' Have cells that are no longer duplicates to not be highlighted'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For i = 0 To UBound(ws)
Sheets(ws(i)).Range(DupCells).Interior.ColorIndex = 0
Next i
'''''''''''''''''''''''''''''''
'Highlight all duplicate cells'
'''''''''''''''''''''''''''''''
For i = 0 To UBound(ws)
For Each CheckCell In Sheets(ws(i)).Range(DupCells)
If CheckCell.Interior.ColorIndex <> 34 Then
For j = 0 To UBound(ws)
For Each rngFound In Sheets(ws(j)).Range(DupCells)
If j = i Then
If CheckCell.Address <> rngFound.Address _
And LCase(Trim(rngFound.Value)) = LCase(Trim(CheckCell.Value)) Then
CheckCell.Interior.ColorIndex = 34
rngFound.Interior.ColorIndex = 34
End If
ElseIf LCase(Trim(rngFound.Value)) = LCase(Trim(CheckCell.Value)) Then
CheckCell.Interior.ColorIndex = 34
rngFound.Interior.ColorIndex = 34
End If
Next rngFound
Next j
End If
Next CheckCell
Next i
End Sub