How can I make the following code work together?
Thanks
Sub Range()
Dim Values As Range
Set Values = Sheets("Fahey Procedure List").Range("c1:c4000")
ActiveWorkbook.Names.Add Name:="Values", RefersTo:=Values
End Sub
Sub Highlight_Duplicates(Values As Range)
Static blnColor As Boolean
'
' Make sure there's no highlighting already in our range:
Values.Interior.ColorIndex = xlColorIndexNone
For Each Cell In Values.Cells
'
' If we're on an un-highlighted cell...
If Cell.Interior.ColorIndex = xlColorIndexNone Then
'
' ...see if it is unique or if it has any duplicates:
If WorksheetFunction.CountIf(Values, Cell.Value) > 1 Then
'
' Toggle between the two colors:
If blnColor Then
Application.ReplaceFormat.Interior.ColorIndex = 6
Else
Application.ReplaceFormat.Interior.ColorIndex = 7
End If
'
' Highlight all duplicate cells:
Cells.Replace What:=Cell.Value, Replacement:=Cell.Value, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
blnColor = Not (blnColor)
End If
Else
'
' ...Else we're on a cell that has already been highlighted;
' we already know it's a duplicate so do nothing else to it.
End If
Next Cell
End Sub
Thanks
Sub Range()
Dim Values As Range
Set Values = Sheets("Fahey Procedure List").Range("c1:c4000")
ActiveWorkbook.Names.Add Name:="Values", RefersTo:=Values
End Sub
Sub Highlight_Duplicates(Values As Range)
Static blnColor As Boolean
'
' Make sure there's no highlighting already in our range:
Values.Interior.ColorIndex = xlColorIndexNone
For Each Cell In Values.Cells
'
' If we're on an un-highlighted cell...
If Cell.Interior.ColorIndex = xlColorIndexNone Then
'
' ...see if it is unique or if it has any duplicates:
If WorksheetFunction.CountIf(Values, Cell.Value) > 1 Then
'
' Toggle between the two colors:
If blnColor Then
Application.ReplaceFormat.Interior.ColorIndex = 6
Else
Application.ReplaceFormat.Interior.ColorIndex = 7
End If
'
' Highlight all duplicate cells:
Cells.Replace What:=Cell.Value, Replacement:=Cell.Value, LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
blnColor = Not (blnColor)
End If
Else
'
' ...Else we're on a cell that has already been highlighted;
' we already know it's a duplicate so do nothing else to it.
End If
Next Cell
End Sub