+ Reply to Thread
Results 1 to 16 of 16

Difference between two dates where some cells are blank

  1. #1
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Difference between two dates where some cells are blank

    Hi everyone,

    In column 'B', I have dates in some cells (e.g. "21/10/2017"), whereas other cells are blank.

    In column 'A', I have the formula "=A2", =A3", etc.

    In column 'I' is the formula "=TODAY()-A2" (or ="TODAY()-A3", and so on). This works fine where column 'A' contains a date, but when column 'A' contains no displayed data, column it displays "43034".

    I need column 'I' to display either a number ("5" for example), or to be blank.

    Can anyone help with this? In my case, what I refer to above as 'Column B' is actually on a different sheet within the same workbook, I have just simplified things for the sake of this example).

    Thanks and regards,

    Andy

  2. #2
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Difference between two dates where some cells are blank

    I'm confused about the formula in column A. Nevertheless, this should do what you are looking for.

    I2 =IF(A2="","",TODAY()-A2)

    That is: "If column A is blank then return blank, otherwise return TODAY()-A2."

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Difference between two dates where some cells are blank

    Yes. It might be easier to follow with a sample sheet (always a VERY good way of getting a rapid response).

    Will you please attach a SMALL sample Excel workbook (10-20 rows of data is usually enough)? Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).


    Unfortunately the attachment icon doesn't work at the moment. So, to attach an Excel file you have to do the following: Just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Difference between two dates where some cells are blank

    Thanks 63falcondude,

    Sorry, that was a typo:

    "In column 'A', I have the formula "=A2", =A3", etc."
    Should read:
    In column 'A', I have the formula "=B2", =B3", etc.

    I tried the formula you suggested, but it displays "43034" in rows where column 'A' is 'blank'. 43034 is today's date, formatted as a number. Please note that, as mentioned above, the 'blank' cells in column 'A' contain a formula. If I delete the formula so the cell is empty as opposed to just not displaying anything, your formula works fine and gives me a blank cell in column 'I'.

  5. #5
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Difference between two dates where some cells are blank

    It's difficult to diagnose without seeing a sample spreadsheet.

    Try this instead:

    I2 =IF(B2="","",TODAY()-A2)

    If this doesn't work, please upload a small representative sample of your workbook along with the desired outcome of the formula.

  6. #6
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Difference between two dates where some cells are blank

    Please see attached example.
    Attached Files Attached Files

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Difference between two dates where some cells are blank

    Try:

    =IF(A2=0,"",TODAY()-A2)

  8. #8
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Difference between two dates where some cells are blank

    You have something going on in your 'Orders' worksheet that displays 0 as blank. I think that has something to do with the issue.

    When I move the data into a new worksheet, the formula suggested in post #2 works as expected.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Difference between two dates where some cells are blank

    That said... it's advsable to use this in A2, copied down:

    =IF(Accounts!A2>0,Accounts!A2,"")

    and this in I2, copied down:

    =IF(A2="","",TODAY()-A2)

    otherwise you'' run into the same problem later...

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Difference between two dates where some cells are blank

    try this one: =IF(LEN(A2)=1,"",TODAY()-A2) and copy down

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,054

    Re: Difference between two dates where some cells are blank

    I beg to disagree Sandy. It's better to get rid of the problem at source... as per Post 9

  12. #12
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Difference between two dates where some cells are blank

    Thanks everybody for your input, I really appreciate it. sandy666, I went with your solution and it works perfectly.

    Out of interest, can anyone offer a brief summary of how the LEN function is used? I have never come across it before, plus it might be helpful to anyone who reads this post in the future.

  13. #13
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: Difference between two dates where some cells are blank

    aglawrence, I am assuming that when trying to pull the dates, some of the cells showed up as 0 so you changed the settings for the entire worksheet to make 0 show as blank.

    You could have done that in the formulas. Otherwise, you may (and probably will) experience unexpected issues in the future (like you did here).

  14. #14
    Forum Contributor
    Join Date
    09-28-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    141

    Re: Difference between two dates where some cells are blank

    Thanks 63falcondude, that's a good point.

    Glenn, your point in post #9 does make sense and I will test this out shortly.

  15. #15
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Difference between two dates where some cells are blank

    Quote Originally Posted by aglawrence View Post
    Thanks everybody for your input, I really appreciate it. sandy666, I went with your solution and it works perfectly.

    If that takes care of your original question, & to say Thanks, please click on Add Reputtion (bottom left corner of the post of the person(s) who helped you)
    then select Thread Tools from the menu (top right corner of your thread) and mark this thread as SOLVED.
    If you did it - ignore it.
    Thank you.

  16. #16
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Difference between two dates where some cells are blank

    Here is extended: =IF(OR(AND(CELL("format",A2)="D1",LEN(A2)=1),ISBLANK(A2),A2="")),"",TODAY()-A2))
    because of date format, len, real blank and empty string
    Last edited by sandy666; 10-26-2017 at 05:41 PM.

+ 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: 3
    Last Post: 10-18-2017, 09:55 AM
  2. [SOLVED] Difference Between Two Dates/Times In Two Cells
    By Logit in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-29-2016, 07:26 PM
  3. [SOLVED] If dates are blank then in that date row all rightside cells should be blank.
    By Sekars in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 04-04-2016, 03:19 PM
  4. Replies: 5
    Last Post: 08-07-2015, 10:05 PM
  5. Replies: 1
    Last Post: 05-14-2014, 05:02 AM
  6. Cant find how to get average dates difference between averaged cells, w/out extra cells
    By jeremyharrisonspo in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-10-2014, 08:20 PM
  7. Replies: 0
    Last Post: 09-27-2012, 01:38 AM

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