+ Reply to Thread
Results 1 to 6 of 6

Delete Duplicate Rows Based on Column B not working properly?

  1. #1
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Red face Delete Duplicate Rows Based on Column B not working properly?

    Hi guys,

    I managed to dig up and put together the following macro to clean up some data so I can see only original and no duplicates but the delete duplicates based on column B portion of the macro seems like it's being cut and skips some data.

    here's a link for the excel files called "avails" and results after called "after"

    https://drive.google.com/open?id=1KQ...be6fNAJsqL7FbE

    The basic gist of the macro is to remove all rows that have "National Toronto" and "House Radio" in column A and also remove any rows that have duplicates in column B so I'm left only with original Advertisers.

    For what ever reason the remove duplicates portion only works partially as after running the macro the following is missing from the results:

    Korissa Siscou-Cruise Holidays of Clarkson
    Lynn gunn-Gallery 121
    Sophia Novanksy-vistaprint
    Steve Mark-Capitol Theatre...
    Susan Holden-The Gravenhurst Opera House

    and here is my macro:

    Sub MissingRemoveDupes()
    '
    ' MissingRemoveDupes Macro
    '

    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$O$940").RemoveDuplicates Columns:=2, Header:=xlYes
    Columns("G:G").Select
    Selection.Delete Shift:=xlToLeft
    Columns("M:M").Select
    Selection.Delete Shift:=xlToLeft
    Selection.Delete Shift:=xlToLeft
    Columns("L:L").EntireColumn.AutoFit
    Columns("K:K").Select
    Selection.Delete Shift:=xlToLeft


    Dim c As Range
    Dim SrchRng

    Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
    Do
    Set c = SrchRng.Find("House Radio", LookIn:=xlValues)
    If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing

    Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
    Do
    Set c = SrchRng.Find("National Toronto", LookIn:=xlValues)
    If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing


    End Sub
    I can't figure out why it's doing this, can someone help me write or correct the code so it will work properly?

    Thanks in advance!

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,098

    Re: Delete Duplicate Rows Based on Column B not working properly?

    How about
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: Delete Duplicate Rows Based on Column B not working properly?

    Quote Originally Posted by Fluff13 View Post
    How about
    Please Login or Register  to view this content.
    YES! That worked perfectly but how do I make it so it will work on any active sheet?

    Here's my attempt at it but it didn't work:

    Sub MissingRemoveDupes()


    ActiveSheet.Range("A1:M1").AutoFilter 1, Array("House Radio", "National Toronto"), xlFilterValues
    AutoFilter.Range.Offset(1).EntireRow.Delete
    AutoFilterMode = False
    Range("A1:M1").EntireColumn.RemoveDuplicates 2, xlYes
    Columns(12).Delete
    Columns(7).Delete

    End Sub

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,098

    Re: Delete Duplicate Rows Based on Column B not working properly?

    Just change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Also when posting code please use Code Tags, the # icon in the reply window, rather than quotes tags
    Cheers

  5. #5
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: Delete Duplicate Rows Based on Column B not working properly?

    Quote Originally Posted by Fluff13 View Post
    Just change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Also when posting code please use Code Tags, the # icon in the reply window, rather than quotes tags
    Cheers
    AWESOME! Thank you so much! +Rep!

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,098

    Re: Delete Duplicate Rows Based on Column B not working properly?

    You're welcome & thanks for the feedback

+ 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. [SOLVED] Delete rows based on duplicate column values?
    By Casey825 in forum Excel General
    Replies: 11
    Last Post: 12-19-2017, 07:10 PM
  2. Delete rows based on duplicate names in 1 column if they contain a value in a second ?
    By myk2thestar23 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-25-2017, 04:51 PM
  3. Delete Duplicate rows with duplicate in 1 column based on value from another column
    By CraigR&M in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2016, 04:36 PM
  4. Delete Duplicate rows with duplicate in 1 column based on value from another column
    By CraigR&M in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-30-2016, 02:06 PM
  5. [SOLVED] UDF to delete all duplicate rows in a Column but one if cell value = myString, not working
    By capson in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-25-2015, 06:13 PM
  6. Replies: 1
    Last Post: 11-23-2015, 03:26 PM
  7. Replies: 5
    Last Post: 05-29-2006, 09:25 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