Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2003, 05:02 PM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Searching for Duplicates in A range of Cells

I am trying to create a code which will search for duplicates and then delete the duplicate row from the worksheet in excel.

Betsy
 
Old October 23rd, 2003, 01:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Select the area to be examined, either manually or by code, and run this code:

Sub RemoveDuplicatesAndRows()

Dim SelectedCells As Range
Dim Cell As Range
Dim Item
Dim i As Long
Dim NoDuplicates As New Collection

Set SelectedCells = Selection
        On Error Resume Next

    For Each Cell In SelectedCells
        NoDuplicates.Add Cell.Value, CStr(Cell.Value)
    Next Cell

    On Error GoTo 0

    Selection.ClearContents
    For Each Item In NoDuplicates
        i = i + 1
        Selection.Cells(i, 1) = Item
    Next

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Yes to duplicates MMJiggy62 Beginning VB 6 3 July 14th, 2006 11:51 AM
Searching a range in a worksheet tiyyob Excel VBA 2 January 13th, 2006 11:26 PM
checking for duplicates jammykam Access 3 October 2nd, 2003 08:06 PM
Deleting Duplicates ioates SQL Server 2000 5 August 31st, 2003 10:18 AM
Duplicates ashley_y Access 11 August 14th, 2003 03:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.