+ Reply to Thread
Results 1 to 6 of 6

If difference between 2 dates follows criteria then delete values

  1. #1
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    If difference between 2 dates follows criteria then delete values

    Hi

    I have this input file (please see below picture and attachment)

    I have this code:

    Please Login or Register  to view this content.
    Alternatively could this be done when the difference between 2 dates is <2 days to delete the entire above row where the difference occurs?

    Below is the Input, the Yellow cells (the above cells where the difference between 2 dates is <2 days) are expected to be deleted because the Red cells indicate a difference <2 days between 2 dates
    Input.JPG


    Output of the code (please see below) is a bit faulty as it adds "delete this" on both rows where the date difference is <2 days. It should "delete this" just on the top row where the difference occurs.


    Output.JPG


    I added the "delete this" instead of blank value just for the sake of being more visible.

    Alternatively, the whole top row where the difference occurs could be deleted if it would be easier.



    Many thanks in advance.
    All the best,
    Gordon
    Attached Files Attached Files
    Last edited by Gordon85; 03-31-2020 at 03:09 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: If difference between 2 dates follows criteria then delete values

    Your data does not lend itself to actually figuring out what you want - you need to have the date of the rental, and the date of the return. Saying it was rented on Wednesday and returned on Thursday is meaningless if the Thursday is the next week instead of the next day. Your "code" compares the value to Date, which is today, and does nothing else.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Re: If difference between 2 dates follows criteria then delete values

    Hello and apologies.

    I updated post #1 with images and code.

    If I replace

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    it just shifts the delete range but it still deletes values from 2 rows such as that, deletes the top row where the difference occurs (which is good), but also the row above it (which is bad)

    The code has to go through all the column B and detect if the difference between the 2 consecutive dates (i, i+1) is <2 days, if it is so, then delete the value of the C cell on the associated i row, or alternatively delete just the entire i row (top row) if it is easier.


    Any help would be appreciated.

    Thank you!
    Gordon
    Last edited by Gordon85; 03-31-2020 at 03:43 AM.

  4. #4
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Re: If difference between 2 dates follows criteria then delete values

    Solved as per below:
    Please Login or Register  to view this content.
    Last edited by Gordon85; 03-31-2020 at 06:20 AM.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,936

    Re: If difference between 2 dates follows criteria then delete values

    Here is an alternative that deletes the entire row - but only if A is the same (just in case)

    Please Login or Register  to view this content.
    This version ignores what't in A

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-30-2020
    Location
    Planet Earth
    MS-Off Ver
    2016
    Posts
    96

    Re: If difference between 2 dates follows criteria then delete values

    Thank you, appreciated! It works! Rep+

+ 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] Difference between dates
    By Sekars in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-30-2016, 09:47 AM
  2. [SOLVED] Difference between two dates
    By ckk403 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-24-2013, 06:02 PM
  3. Detecting where to Insert, Delete, or Rearrange Rows using Values and Dates
    By StudentTeacher in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-28-2012, 01:02 PM
  4. Difference between two dates
    By Karthick.icwa in forum Excel General
    Replies: 7
    Last Post: 06-13-2012, 11:45 PM
  5. difference between two dates
    By allems in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2011, 06:09 AM
  6. The difference between two dates
    By hesham63 in forum Excel General
    Replies: 5
    Last Post: 07-29-2011, 04:15 PM
  7. difference between two dates
    By dhouston1000 in forum Excel General
    Replies: 2
    Last Post: 08-24-2005, 07:05 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