+ Reply to Thread
Results 1 to 9 of 9

Delete rows where column A has duplicates based on values in Column B

  1. #1
    Registered User
    Join Date
    07-22-2013
    Location
    Chennai India
    MS-Off Ver
    Excel 2010
    Posts
    4

    Delete rows where column A has duplicates based on values in Column B

    Hi,

    I am new to this forum and I am trying to acheive something in excel vba with no luck. I have explained the issue below. Appreciate your inputs.

    when there is a duplicate in Column A , the column B values of those rows should be compared the row with high priority value should be retained and the low priority one has to be deleted. For Example,

    Column A Column B

    1 -------> Critical
    2 ----------> High
    3 -----------> Medium
    4 ----------> Low
    5 -----------> Low
    1 ---------> High
    1 --------> Medium
    1--------->Low
    2 --------> Low
    2--------->Medium
    4 ---------> High


    in the above example, Column A has the value "1" with many values in corresponding column B. When executed, it should retain

    1 -------> Critical
    2 ----------> High
    3 -----------> Medium
    4 ---------> High
    5 -----------> Low
    The priority Order of column B values are

    1) Crictical - Priority 1
    2) High - Priority 2
    3) Medium - Priority 3
    4) Low - - Priority 4

    Hence, the duplicates in Column A will be checked for the priority and the high priority rows are retained and the other duplicate rows should be deleted.

    FYI, The sheet is sorted by Column A

    Thanks for the help.

    Cheers,
    Raj

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,776

    Re: Delete rows where column A has duplicates based on values in Column B

    Please attach a sample workbook with enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Note: Please don't attach documents containing confidential data like (address, telephone, ID#s, etc.).


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    07-22-2013
    Location
    Chennai India
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Delete rows where column A has duplicates based on values in Column B

    Hi,

    I am posting both before execution and after execution sheets along
    Attached Files Attached Files

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,776

    Re: Delete rows where column A has duplicates based on values in Column B

    Try the below code...

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

  5. #5
    Registered User
    Join Date
    07-22-2013
    Location
    Chennai India
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Delete rows where column A has duplicates based on values in Column B

    Hi,

    Could you explain me how this syntax works. How will it apply the priority on the Column "B" values

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,776

    Re: Delete rows where column A has duplicates based on values in Column B

    It will sort the data based on column-B A-Z and Column-A A-Z and removes the duplicates from it.

  7. #7
    Registered User
    Join Date
    07-22-2013
    Location
    Chennai India
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Delete rows where column A has duplicates based on values in Column B

    Hi,

    The problem is the values in Column B would necessarily not be the same values. Lets say if a new value called "Pending" is there for the same ID with another status "Low", the pending row should stay and the "Low" should go. In other words, they values in Column B are maximum 4 or values with prority 1 to Priority 5. Based on the available values in the sheet, the row with the highest priority should stay

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,776

    Re: Delete rows where column A has duplicates based on values in Column B

    Sorry I can't help you should have shown the sample data with different permutations while posting the sample data.

    I hope someone will take care of your new requirement.

  9. #9
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Delete rows where column A has duplicates based on values in Column B

    try this code
    note that for your sample data it gives a different result for one value (medium instead of your low for ID INC000000563322), but the error in that case seems to be yours rather than mine
    to add any more priority criteria, put them in the correct order in the array p
    Please Login or Register  to view this content.
    Last edited by kalak; 08-08-2013 at 08:53 AM.

+ 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] 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
  2. [SOLVED] Macro to count unique values in a column, enter it in next column, then delete duplicates
    By pmorisse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-25-2013, 03:27 PM
  3. Delete Rows based on values present in another column
    By booo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2011, 05:19 PM
  4. Delete rows based on Column B Values
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2011, 01:49 PM
  5. Delete Rows based on Values in a column
    By Recycle_Bin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2009, 04:36 PM

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