+ Reply to Thread
Results 1 to 6 of 6

Delete Duplicate rows with conditional formula

  1. #1
    Registered User
    Join Date
    11-30-2016
    Location
    Dundee
    MS-Off Ver
    MS Office
    Posts
    5

    Delete Duplicate rows with conditional formula

    Hi,

    New to this, hoping somebody can advise.

    I have a 37,000 row data table with stock and prices. I am trying to delete duplicate stock items (over 7,000) which show the higher price in a column. I can't see any place I can do that. Any advice or help would be greatly appreciated.

    Thanks,

    Craig.

  2. #2
    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: Delete Duplicate rows with conditional formula

    depending on what the item is that indicates they are duplicates (say stock number in column A for example) you could put a formula like this somewhere to indicate which are duplicates... =COUNTIF($A$2:A2,A2) and drag down. That will give you 1s and 2s and higher for duplicates. 1s are first, 2s and higher are duplicates.
    Then you could sort them based on those numbers and the duplicates would all be at the bottom (if you sort ascending) then you could highlight the whole bunch and delete them.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Registered User
    Join Date
    11-30-2016
    Location
    Dundee
    MS-Off Ver
    MS Office
    Posts
    5

    Re: Delete Duplicate rows with conditional formula

    Hi Sambo,

    Thanks for the reply and you're correct the duplicates are indicated in column A per stock number. However I need for example, if there is 5 rows with the same stock number, I need to keep the row with the lowest price (in separate column) and delete the 4 other rows which would have higher prices?

    Thanks.

  4. #4
    Registered User
    Join Date
    11-30-2016
    Location
    Dundee
    MS-Off Ver
    MS Office
    Posts
    5

    Re: Delete Duplicate rows with conditional formula

    Hi, hoping for a solution,

    I have now attached my file.

    I need a formula or macro to identify duplicate rows in column A, then for all rows that contain the same data in column A (could be 4 or 5 lines), I want the whole row deleted based on criteria of what has the lowest value in column F.

    Many thanks
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,522

    Re: Delete Duplicate rows with conditional formula

    This proposed solution employs several helper columns, which may be hidden/moved for aesthetic purposes. The first helper column (I) identifies duplicates using the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The second and third helpers will then get the 'Part' and 'GBP' for the duplicates using formulas similar to:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The fourth helper identifies 'singles' and lowest price duplicates using the formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    A table of singles and lowest cost duplicates is then created in columns M:T using the array entered formula*:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    *Array entered formulas are activated by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Note: the calculations needed to create the table will, or at least on my laptop did, take quiet a long time.
    Note: I had to greatly reduce the size of the attached file so that it would upload, hopefully there is enough left to see how the formulas work.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,135

    Re: Delete Duplicate rows with conditional formula

    In column I

    =COUNTIF($A$2:$A$13000,A2)

    Copy down

    in column J

    =IF(A2=A1,IF(MIN(OFFSET($F$2,MATCH(A2,$A$2:$A$13000,0)-1,0,COUNTIF($A$2:$A$13000,$A2)))=F2,F2,""),"")

    Copy down

    Filter on Column I > 1 and column J will have minimum value for the duplicates.

    NOTE: this may take a few seconds to complete but it did the 12500 rows in your sample in about 5 seconds.
    Attached Files Attached Files

+ 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. Add values from duplicate rows and delete duplicate
    By jane204 in forum Excel General
    Replies: 3
    Last Post: 11-20-2016, 08:36 AM
  2. Formula to Tag or Delete Duplicate keeping the Rows with paticular Data
    By tesloid69 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-22-2016, 05:10 PM
  3. [SOLVED] Delete rows based on duplicate cell, but leaving first and last duplicate.
    By LadyNicole in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 05:07 AM
  4. VBA helps needed to Sum duplicate values and delete duplicate rows
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2013, 11:40 PM
  5. Replies: 5
    Last Post: 11-12-2012, 08:38 PM
  6. [SOLVED] Sum Duplicate values then delete duplicate rows
    By keekdapolak in forum Excel General
    Replies: 7
    Last Post: 09-20-2012, 02:57 PM
  7. Sum and delete Duplicate Rows VBA MACRO FORMULA
    By ARNO in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-11-2010, 11:56 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