|
|
|
|
|
|
Excel
|
Delete Duplicated Entries In Cells
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2003
|
Submitted by:
|
johnske
|
Description:
|
Any duplicated entries are deleted and a message box tells you how many were deleted.
|
Discussion:
|
You may have a list of things, but you want to ensure each entry is unique. By default, this searches from left to right and top to bottom (as in normal reading order) and deletes any duplicated entries, leaving only the first such entry found.
|
Code:
|
instructions for use
|
Option Explicit
Sub DeleteDuplicateEntries()
Dim Cell As Range, Cel As Range, N&
Application.ScreenUpdating = False
N = 0
For Each Cell In Selection
If Cell <> Empty Then
For Each Cel In Selection
If Cel <> Empty And _
Cel.Value = Cell.Value And _
Cel.Address <> Cell.Address Then
Cel.ClearContents
N = N + 1
End If
Next Cel
End If
Next
Application.ScreenUpdating = True
MsgBox "There were " & N & " duplicated entries deleted"
End Sub
|
How to use:
|
- Open an Excel workbook
- Select Tools/Macro/Visual Basic Editor
- In the VBE window, select Insert/Module
- Copy and paste the code above into the Module
- Now select File/Close and Return To Microsoft Excel
- Dont forget to save your changes...
|
Test the code:
|
- Select the area where there may be duplicates you want deleted
- Go to Tools/Macro/Macros.../DeleteDuplicateEntries/Run
- (Or download the attachment to test this out)
|
Sample File:
|
DeleteDuplicates.zip 6.71KB
|
Approved by mdmackillop
|
This entry has been viewed 227 times.
|
|