+ Reply to Thread
Results 1 to 5 of 5

Nested IF function to stop TODAY() updating to TODAY's date

Hybrid View

  1. #1
    Registered User
    Join Date
    05-12-2015
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    2

    Nested IF function to stop TODAY() updating to TODAY's date

    Hi all,

    Question related to the TODAY() formula. I have a very basic table with 2 columns: TASK and DATE

    The idea is: when you enter a task in the TASK column, it automatically enters the date on which the task was added to the list.
    I manage this with the formula:
    =IF(NOT(ISBLANK(A2));TODAY();"")
    Capture.PNG


    Problem: when you open the Excel, it recalculates everything and automatically changes every old date into TODAY()'s date. It basically runs the formula again.

    I thought about solving it with a nested IF function, but I don't get my head around it, and it feels like I am building a loop (I know the parentheses are not ok, just trying to explain the formula.
    =IF(NOT(ISBLANK(A2));IF(ISBLANK(B2);TODAY(););)
    In words:
    If A2 is not blank
    >>>>THEN
    >>>>IF B2 is blank
    >>>>>>>THEN add today's date,
    >>>>>>>otherwise (IF B2 is not blank) don't do anything
    otherwise (if A2 is blank)
    THEN leave B2 empty


    A would need a solution without VBA if possible ...

    Thanks in advance!
    Last edited by zipke; 05-04-2020 at 03:34 PM.

  2. #2
    Registered User
    Join Date
    04-26-2020
    Location
    Massachusetts
    MS-Off Ver
    Office 365
    Posts
    93

    Re: Nested IF function to stop TODAY() updating to TODAY's date

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. 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 shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested IF function to stop TODAY() updating to TODAY's date

    You would need to use VBA for this task, likely the Worksheet_Change event to see if a cell in column A has changed, and if so update the cell in column B of that row to reflect the date A2 was entered. (You may also want to have code to update the date if A2 was already filled and has now changed (if the same, don't update date). And if deleted, remove the date.)

  4. #4
    Registered User
    Join Date
    05-12-2015
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    2

    Re: Nested IF function to stop TODAY() updating to TODAY's date

    Quote Originally Posted by way2020 View Post
    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. 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 shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    The file is attached with the Before and After tab.
    Attached Files Attached Files

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Nested IF function to stop TODAY() updating to TODAY's date

    Using a combination of the Worksheet_Change, Worksheet_SelectionChange and a global variable (in a module), this may work for you.
    The following code goes into the worksheet code module for the sheet with your tasks/dates (right-click tab, select View Code, paste this code into the VB editor)
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    ' Don't run macro if multiple cells changed at once
    If Target.Cells.Count > 1 Then Exit Sub
    
    ' Check if the Target cell (acted upon cell) intersects with Column A.
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        
        ' If target cell is blank, delete date from column B.
        If Target.Value = "" Then
            Target.Offset(0, 1).Value = ""
        
        ' Else, if target cell value is different from lastCell variable
        ' that was updated when you selected the cell, then update the
        ' date in column B.
        ElseIf Target.Value <> lastCell Then
            Target.Offset(0, 1).Value = Date
            
        End If
    
    End If
        
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    lastCell = Target.Value
    End Sub
    This line of code sets a global variable, and goes in a module. In the VB Editor, click Insert > Module, then paste this line. It basically captures the cell value of any cell you click on while on the sheet with the 'SelectionChange' event code. This is so it can compare the previous value with the new value. (If the cell was "Test Task 1", and you re-type "Test Task 1", you probably don't want the date to change, hence this check. If it was "Test Task 1" and now it's "Test Task 2", a new date will appear in column B.)
    Global lastCell As Variant

+ 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: 10
    Last Post: 09-06-2023, 08:19 PM
  2. [SOLVED] Stop Today Date Function From Updating When Coping Text
    By stoicy in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-24-2016, 05:25 PM
  3. Stop today function from updating daily
    By ExcelGuroo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-18-2015, 01:44 PM
  4. Please help me with VBA code to stop data updating using today's date.
    By Vickymabo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2015, 05:54 PM
  5. Looking for VBA code to stop data updating using today's date.
    By Vickymabo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2015, 02:34 PM
  6. Looking for VBA code to stop data updating using today's date.
    By Vickymabo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2015, 02:30 PM
  7. [SOLVED] How do I stop today() from updating date on saved spreadsheets?
    By lionmark in forum Excel General
    Replies: 2
    Last Post: 01-03-2005, 09:06 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