J
Jennifer Johnson
I've used this Q page from the knowledge base: Microsoft
Knowledge Base Article - 213355. It looks for duplicates
in a column.
To view the entire article go to the Microsoft Support
page at http://support.microsoft.com and search by the
article number.
Below is the sample macro written in VB:
For the macro to work correctly, make sure both of the
following conditions have been met:
The column in which you want to find duplicates has been
sorted based on values in that column.
-and-
The first cell in the column in which you want to find
duplicates is selected.
===============================
Sample Visual Basic Code
Sub FindDups ()
'
' NOTE: You must select the first cell in the column and
' make sure that the column is sorted before running
this macro
'
ScreenUpdating = False
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
Do While ActiveCell <> ""
If FirstItem = SecondItem Then
ActiveCell.Offset(Offsetcount,0).Interior.Color =
RGB(255,0,0)
Offsetcount = Offsetcount + 1
SecondItem = ActiveCell.Offset(Offsetcount,
0).Value
Else
ActiveCell.Offset(Offsetcount, 0).Select
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1,0).Value
Offsetcount = 1
End If
Loop
ScreenUpdating = True
End Sub
Knowledge Base Article - 213355. It looks for duplicates
in a column.
To view the entire article go to the Microsoft Support
page at http://support.microsoft.com and search by the
article number.
Below is the sample macro written in VB:
For the macro to work correctly, make sure both of the
following conditions have been met:
The column in which you want to find duplicates has been
sorted based on values in that column.
-and-
The first cell in the column in which you want to find
duplicates is selected.
===============================
Sample Visual Basic Code
Sub FindDups ()
'
' NOTE: You must select the first cell in the column and
' make sure that the column is sorted before running
this macro
'
ScreenUpdating = False
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
Do While ActiveCell <> ""
If FirstItem = SecondItem Then
ActiveCell.Offset(Offsetcount,0).Interior.Color =
RGB(255,0,0)
Offsetcount = Offsetcount + 1
SecondItem = ActiveCell.Offset(Offsetcount,
0).Value
Else
ActiveCell.Offset(Offsetcount, 0).Select
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1,0).Value
Offsetcount = 1
End If
Loop
ScreenUpdating = True
End Sub