+ Reply to Thread
Results 1 to 6 of 6

Delete Row if There is a Duplicate Number in same Column

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    Wisconsin, WI
    MS-Off Ver
    Excel 2007
    Posts
    37

    Delete Row if There is a Duplicate Number in same Column

    I understand filtering will accomplish this but a macro would save time.

    My data is in Column "B" that contains ID#. If there is a duplicate ID# in column B, delete the row, but keep one. In addition, I do not want to delete blank cells in Column "B" and non number data.

    Before:
    XXXXX
    35069
    35070

    35855
    35855
    XXXXX

    35865
    35867

    After:
    XXXXX
    35069
    35070

    35855
    XXXXX

    35865
    35867

    Thanks!

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Delete Row if There is a Duplicate Number in same Column

    Try this code........
    Sub deleteduplicates()
    Dim rng As Range
    Dim lr As Long
    lr = Cells(Rows.Count, 2).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = lr To 2 Step -1
        Set rng = Range("B2:B" & lr)    
        If IsNumeric(Cells(i, 2).Value) = True And WorksheetFunction.CountIf(rng, Cells(i, 2).Value) > 1 Then
        Cells(i, 2).EntireRow.Delete
        End If
    Next i
    Application.ScreenUpdating = True
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    02-19-2013
    Location
    Wisconsin, WI
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Delete Row if There is a Duplicate Number in same Column

    Compile error:
    Variable not defined

    What other information do you need?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Delete Row if There is a Duplicate Number in same Column

    Quote Originally Posted by PaulLor89 View Post
    Compile error:
    Variable not defined

    What other information do you need?
    Add Dim i as Long

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Delete Row if There is a Duplicate Number in same Column

    The code is running perfect at my end.

    See the attached sheet.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-19-2013
    Location
    Wisconsin, WI
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Delete Row if There is a Duplicate Number in same Column

    Thank you! Seems to be working!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Delete duplicate cells in column and everything after
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2013, 04:43 PM
  2. [SOLVED] If there is a duplicate in column A delete that row
    By djfscouse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-19-2012, 01:04 PM
  3. How to automatically delete duplicate and put in a new column
    By AWFrenz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-01-2012, 08:48 AM
  4. Delete Duplicate column's row
    By prayami in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2011, 10:35 PM
  5. Delete row where there is duplicate data in Column E
    By SITCFanTN in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-04-2006, 04:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1