+ Reply to Thread
Results 1 to 24 of 24

Find duplicates in column D and delete only if?

  1. #1
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Find duplicates in column D and delete only if?

    Hi, I could really use some advice.

    1. Find duplicate item numbers in column D.
    2. Then delete the rows with the duplicate item numbers but only if they are listed as "sold out" in column F.

    Thank you for your time
    Kim

  2. #2
    Registered User
    Join Date
    01-12-2021
    Location
    South Africa
    MS-Off Ver
    Office 2016
    Posts
    18

    Re: Find duplicates in column D and delete only if?

    Welcome Tim

    In order to get any assistance please read the forum rules i.e. add a excel wb with non confidential or private data then we can help you.


    R

  3. #3
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Find duplicates in column D and delete only if?

    you could use something like this in another column to target them... =IF(AND(COUNTIF($D$2:D2,D2)>1,F2="sold out"),"delete","")
    is that something you could use?

    but a formula will not delete rows, for that you need VBA.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  4. #4
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Added: Never mind this idea is not going to work. I have to go back to find matches and delete if.


    I was thinking I could combine all rows with duplicate values in column D. Then delete all rows with sold out in them. Thoughts?
    Last edited by Kimbersh; 01-29-2021 at 04:14 PM.

  5. #5
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Sorry, I'll read them

  6. #6
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Find duplicates in column D and delete only if?

    Kimbersh, it isn't helpful for you to change prior posts, it leaves those of us attempting to help with disjointed conversations.

    You can do sorts on multiple columns (up to 3) that might help you. But if you no longer have the issue then please mark the post as solved.

  7. #7
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Yap, this is the second time I've messed up today on this forum, sorry. I need to give this forum a break. I was just tossing out an idea which I now know won't work. I know what I want to do but have no clue how to get there so just testing options and seeing what happens. Thanks

  8. #8
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,496

    Re: Find duplicates in column D and delete only if?

    Please don't take my advice as admonishment, it is just advice. AND please don't give up on the forum. We were all new members at one time.

  9. #9
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    I'm not giving up on the forum and I took it as advice. I have too many ideas on how to get where I want to go that it's not a good time to post because I'd just be tossing out ideas. This is something I will have to do daily to upload to the company I work for websites. I know my end goal but I need to figure out how to get there.

    I have a large excel file. In this file column E the Convey # has several matching numbers. They are not duplicates but re-inspection. I need to match those numbers that have PASS in the Inspection Status column H then all the matching number rows are to be deleted. Leaving only the row of with FAIL items that have never passed.

    Attachment 716001

    It Friday... Enjoy your weekends. This old woman needs a drink and to turn off my brain for a few hours before I work on this all weekend on this.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Find duplicates in column D and delete only if?

    Add today’s extra information here and attach a workbook (instructions at the top of the page - no need for a link to DropBox).
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: Find duplicates in column D and delete only if?

    Judging by the file in the other thread, you could use an advanced filter.
    In G2 put
    =COUNTIFS(B2:B86,B2,D2:D86,"Pass")>0

    Then select A2 & on the data tab select Advanced in the Sort & Filter group, make sure the listrange shows your entire data range & then click in the Criteria Range & select range G1:g2 then click Ok.
    You can now delete the visible rows & clear the filter
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Hi, I tried to explain this yesterday but did a horrible job and messed up the thread with other ideas. I made examples and hope I can explain what I need better.

    My goal is every inspection that has PASS at some point, that row is deleted.

    This spreadsheet is a small sample of what I'm working with https://www.dropbox.com/scl/fi/0yhgz...vky4m58pycmsur

    Attachment 716122

    This second example is where I have found the duplicates which are highlighted. https://www.dropbox.com/scl/fi/u45vv...rbl85z4nqczigq


    In this image, you can see the duplicate convey#BC are highlighted with one being FAIL and one being PASS which means both these rows need to be deleted. Note: Some items can be inspected several times before getting a PASS. I can't do it manually because this sheet has 1000's of rows which I will go over a few times a week.

    Attachment 716123

    Once I have deleted all these duplicates with PASS in at least one row. I will delete all PASS items. Leaving only the truly failed items.

    What do I need to learn to do this process?
    Thank you for your time
    Kim

  13. #13
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Sorry, I posted wrong, and not can't find the delete post button. But I will try this next.

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

    Re: Find duplicates in column D and delete only if?

    See post#11, we posted at the same time.

  15. #15
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Find duplicates in column D and delete only if?

    I don't know what happened on this thread, but here is some code in case anybody is interested.

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  16. #16
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Quote Originally Posted by Fluff13 View Post
    Judging by the file in the other thread, you could use an advanced filter.
    In G2 put
    =COUNTIFS(B2:B86,B2,D2:D86,"Pass")>0

    Then select A2 & on the data tab select Advanced in the Sort & Filter group, make sure the listrange shows your entire data range & then click in the Criteria Range & select range G1:g2 then click Ok.
    You can now delete the visible rows & clear the filter
    Couple Questions:

    In =COUNTIFS(B2:B86,B2,D2:D86,"Pass")>0 What does the second B2 for?

    Where did the duplicates that have both FAIL and PASS go?

    Thank you
    Kim

  17. #17
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    WOW I'll probably be back to ask questions because I really want to learn these codes. Thank you so much, I believe it all works perfectly but need to compare my sheets.

  18. #18
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Find duplicates in column D and delete only if?

    Code needed a mod.

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Quote Originally Posted by JLGWhiz View Post
    Code needed a mod.

    Please Login or Register  to view this content.



    Hi, I am trying to learn these codes and have a couple of questions. My questions are marked with >>>>. Attached is a screenshot of my actually headers that I'm working with. I don't understand the (i, 2) parts.


    Capture.PNG


    Sub t()
    Dim i As Long, fn As Range, adr
    With ActiveSheet
    For i = Cells(Rows.Count, 8).End(xlUp).Row To 6 Step -1

    >>> Since in example 1 row 4 is Inspection Status and my full sheet the Inspection Status is E, I change Count 4 to 8.
    >>> Row To 3 Step -1 I would change the 3 to a 6


    If LCase(Trim(.Cells(i, 4).Value)) = "pass" Then

    >>> I change the 4 to an 8 but what does the i stand for? Is it something I need to change?
    >>> I've changed the B to E. What does these mean Cells(i, 2)?

    If Application.CountIf(Range("E:E"), .Cells(i, 2).Value) > 1 Then
    Set fn = .Range("E2:E" & i - 1).Find(.Cells(i, 2).Value, , xlValues, xlWhole)
    If Not fn Is Nothing Then
    adr = fn.Address
    Do
    .Cells(fn.Row, 8) = "Pass"
    Set fn = .Range("E2:E" & i - 1).FindNext(fn)
    Loop While fn.Address <> adr
    End If
    End If
    End If
    Next
    Intersect(.UsedRange, .Range("H:H")).AutoFilter 1, "PASS"
    Intersect(.UsedRange.Offset(1), .Range("H:H")).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilterMode = False
    End With
    End Sub
    Thank you for your time
    Kim

  20. #20
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Hi, what do I search online to learn what the i function is? I've been trying to learn (.Cells(i, 4)

    Thank you
    Kim

  21. #21
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Find duplicates in column D and delete only if?

    Quote Originally Posted by Kimbersh View Post
    Hi, what do I search online to learn what the i function is? I've been trying to learn (.Cells(i, 4)

    Thank you
    Kim
    The value of the variable ' i ' is established by this line of code:
    Please Login or Register  to view this content.
    In this case from the last row with data row number to 3. It decrements automatically on each iteration of the For loop to represent an iteger value, used as the row number in the Cells() syntax. For more information regarding the use of variables in code, I suggest you search on the internet for tutorials that go into detail on creating and using variables in vba.
    Last edited by JLGWhiz; 02-01-2021 at 12:56 PM.

  22. #22
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    Thank you, I've taken several tutorials and will keep this. If you have any thoughts to share I'd really appreciated it. I don't mind doing the work but input is always helpful.

    This is where I'm at now

    Attachment 716428

  23. #23
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Find duplicates in column D and delete only if?

    Quote Originally Posted by Kimbersh View Post
    Thank you, I've taken several tutorials and will keep this. If you have any thoughts to share I'd really appreciated it. I don't mind doing the work but input is always helpful.

    This is where I'm at now

    Attachment 716428
    Don't forget to mark the thread as solved.

  24. #24
    Registered User
    Join Date
    01-03-2021
    Location
    Indiana
    MS-Off Ver
    365
    Posts
    31

    Re: Find duplicates in column D and delete only if?

    I found my mistake. It works!!!!!!

    YYYYYAAAAAA

+ 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. Find duplicates then delete duplicates that match a certain criteria
    By Marvlin in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 06-12-2020, 10:35 AM
  2. [SOLVED] Macro to find duplicates, concatenate cells, then delete old duplicates (2)
    By cny in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2016, 06:05 AM
  3. Macro to find duplicates, concatenate cells, then delete old duplicates
    By givemepuppies in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-04-2016, 02:43 AM
  4. [SOLVED] Find Duplicates in column and then based on row criteria delete the row of that Duplicate
    By bobberuk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2016, 01:56 PM
  5. [SOLVED] Macro to find duplicates, concatenate Unique Values, then delete old duplicates
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:32 PM
  6. [SOLVED] Find duplicates in column A, add values from column B (possibly delete duplicates)
    By luarwhite in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-12-2013, 04:34 PM
  7. [SOLVED] Find duplicates, concatenate into different column, sum and delete duplicates
    By rosannang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-17-2013, 11:23 AM

Tags for this Thread

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