+ Reply to Thread
Results 1 to 6 of 6

How to delete rows based on comparing values in two fields

  1. #1
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    How to delete rows based on comparing values in two fields

    I have an Excel sheet with ID numbers, Dates, and other columns as shown below. I would to remove rows such that I'm left with only one row for each ID number, and it would be the row with the most current date. Can anyone please tell me how this can be done? Thank you!

    ID Date Other columns
    1 5/20/13
    1 12/27/12
    2 2/5/11
    3 9/4/12

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: How to delete rows based on comparing values in two fields

    Here are a couple of options, but they don't actual delete any of the real data in case you actually need it later on.
    Attached Files Attached Files
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to delete rows based on comparing values in two fields

    Thank you, Jeff. Your pivot table shows the ID and Dates exactly exactly as I had intended. However, for each of those three rows, I would like the table to include data from the other columns of my original spreadsheet, as well. When I attempt to add those, there are problems with the layout. I'm rather new to Excel pivot tables, as well!

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: How to delete rows based on comparing values in two fields

    If you could provide a mock up of what you have and what you desire that would help.

    Attach a sample workbook. Make sure there is just 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

  5. #5
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to delete rows based on comparing values in two fields

    I was able to solve this by sorting (by ID and then by Date); then comparing values in the ID field using an If statement and populating a "flag" field as either 1 or 0 (If the ID number in row 2 = the ID number in row 1, flag field = 0, else flag field =1),and the deleting all rows with a flag field value of 0. The result is one row for each ID number (the row with the most recent date), and all other data columns in the spreadsheet hung on for the ride.

    Thank for your help, Jeff. I wasn't aware that I could attach a file to clarify my question--thanks for passing that along!

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: How to delete rows based on comparing values in two fields

    You're welcome…glad you have a workable solution and 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. Replies: 1
    Last Post: 06-26-2012, 08:50 AM
  2. [SOLVED] Help with macro to delete rows based on values
    By jimstrongy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-26-2012, 08:49 AM
  3. VBA/Macro to delete rows based on comparing two dates?
    By tltlk678 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2012, 02:25 AM
  4. Grouping rows based on column values and comparing row values
    By bernborough in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2010, 10:18 AM
  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