+ Reply to Thread
Results 1 to 6 of 6

Count number of days from today

  1. #1
    Registered User
    Join Date
    06-24-2021
    Location
    London, England
    MS-Off Ver
    365
    Posts
    4

    Count number of days from today

    Hi need some help on this equation.
    I have a date in cell B1.
    I have a status cell in C1 which says "completed" or "not completed"
    I need D1 to calculate how many days are between today's date and B1 if C1 shows not completed. If C1 shows completed, the date should should stop counting on the day that the status showed completed.

    for example:
    C1 is Not completed. Cell B1 is 1 Jun 2023. D1 should show 5 days.

    C1 is completed on 4 Jun 2023. Cell B1 is 1 Jun 2023. D1 should show 4 days.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,912

    Re: Count number of days from today

    Welcome to the forum.

    If the task is complete, which cell will show the complete date?

    =IF(C1="Not Completed",(TODAY()-B1)+1,(cell_with_complete_date-B1)+1)

    EDIT:

    the date should should stop counting on the day that the status showed completed.
    This cannot be done without VBA. Just add a column for the completed date - you can set data validation to prompt its being filled in once C1 changes to Completed.
    Last edited by AliGW; 06-05-2023 at 02:18 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Count number of days from today

    Put this in worksheet module (Right click on tab's name, ViewCode then paste this code into)
    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If 
    Target.Address(00) <> "C1" Then Exit Sub
    With Range
    ("D1")
        
    Select Case LCase(Range("C1").Value)
            Case 
    "not completed"
                
    .Formula "= today() - B1 + 1"
            
    Case "completed"
                
    .Value = .Value
        End Select
    End With
    End Sub 
    Quang PT

  4. #4
    Registered User
    Join Date
    06-24-2021
    Location
    London, England
    MS-Off Ver
    365
    Posts
    4

    Re: Count number of days from today

    Hi. Able to guide me on the attached file. I have pasted the code there. Can i also check how can this vba be amended to apply the code to the whole column instead?
    Attached Files Attached Files

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,912

    Re: Count number of days from today

    I have moved your thread. In future, please post in the VBA section for code queries.

  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Count number of days from today

    OK. Like this:

    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If 
    Target.Column And Target.Row 1 Then ' trigger change from C2 downwards
        With Target.Offset(0, 1) '
    next cell in column D
            Select 
    Case LCase(Target.Value)
                Case 
    "not completed"
                    
    .Formula "= today() - " Target.Offset(0, -1).Address "+ 1"
                
    Case "completed"
                    
    .Value = .Value
            End Select
        End With
    End 
    If
    End Sub 
    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. Formula to count number of days in range which are less than today
    By Duke Carey in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 07:05 AM
  2. [SOLVED] Formula to count number of days in range which are less than today
    By Duke Carey in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  3. Formula to count number of days in range which are less than today
    By Duke Carey in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM
  4. Formula to count number of days in range which are less than today
    By zooming in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. Formula to count number of days in range which are less than today
    By zooming in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  6. Formula to count number of days in range which are less than today
    By zooming in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  7. [SOLVED] Formula to count number of days in range which are less than today
    By zooming in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  8. Formula to count number of days in range which are less than today
    By zooming in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-21-2005, 12:05 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