Date and Time Populate based on another cell

pattigander

New Member
Joined
Jun 20, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I have the following formula set up so that when cell A4 is populated B4 is date stamped and if A4 is blank B4 is blank. I also want the date to not change once entered. When I put in the formula I get a circular reference error. Not sure what I am doing wrong...

=IF(A4<>"",IF(B4<>"",B4,TODAY()), "")

Any hep would be appreciated..
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The best way to do TimeStamps is to use VBA. The problem with using functions like "TODAY()" is that they are dynamic and will always return the current date (they are not "frozen/locked" in time, but are constantly recalculated).

Are you agreeable to a VBA solution?
If so, is A4/B4 the only cells you want to apply this logic to, or also other cells on your sheet?
If others, please tell us the exact range this should be applied to.
 
Upvote 0
I have other cells the first is date entered in cell a4:a6 and repeated in cells A9:A50. I am also capturing time stamp when a4:a50 is populated into cell c9:c50. Any help would be greatly appreciated.
 
Upvote 0
Why use two columns for Date/Time stamp when you can do both in a single column, with a value that returns both date and time?

Here is VBA code that should so that on the range you want. Just go to the sheet that you want to apply this to, right-click on the Sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor window that pops-up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
   
'   Specify range to monitor
    Set rng = Range("A4:A6,A9:A50")
   
'   Exit if no cells in watched range updated
    If rng Is Nothing Then Exit Sub

'   Loop through updated cells
    For Each cell In rng
        Application.EnableEvents = False
'       If cell is not blank, add date/time stamp to column B
        If cell <> "" Then
            cell.Offset(0, 1) = Now()
'       If cell is blank, clear date/time stamp from column B
        Else
            cell.Offset(0, 1).ClearContents
        End If
        Application.EnableEvents = True
    Next cell

End Sub
This should run automatically as you make entries into cells A4:A6 and A9:A50.
 
Upvote 0
Solution
Why use two columns for Date/Time stamp when you can do both in a single column, with a value that returns both date and time?

Here is VBA code that should so that on the range you want. Just go to the sheet that you want to apply this to, right-click on the Sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor window that pops-up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
  
'   Specify range to monitor
    Set rng = Range("A4:A6,A9:A50")
  
'   Exit if no cells in watched range updated
    If rng Is Nothing Then Exit Sub

'   Loop through updated cells
    For Each cell In rng
        Application.EnableEvents = False
'       If cell is not blank, add date/time stamp to column B
        If cell <> "" Then
            cell.Offset(0, 1) = Now()
'       If cell is blank, clear date/time stamp from column B
        Else
            cell.Offset(0, 1).ClearContents
        End If
        Application.EnableEvents = True
    Next cell

End Sub
This should run automatically as you make entries into cells A4:A6 and A9:A50.
Thanks. Much appreciated. It worked great.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0
Sorry one other quick question. How do I apply this code to multiple sheets?
Copy that code into the appropriate Sheet module, for each sheet that you want to apply it to.
 
Upvote 0

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top