Returning a date in a cell, but leave blank if no date entered

lojanica

New Member
Joined
Feb 22, 2024
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I am trying to automate some process and minimise data entry using formulas

Does anyone know if you could populate one cell with today date if other cell contain data otherwise keep it blank but to keep day date entry?

For example: B1=IF(ISBLANK(A1),"",TODAY()) - how do i keep date in B1 when data was entered as date will change with current formula to date i open document again.

Thank you

 

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)
Not without using VBA as far as I know. There are several VBA options, probably the easiest being a custom function.

Regards

Murray
 
Upvote 0
Not without using VBA as far as I know. There are several VBA options, probably the easiest being a custom function.

Regards

Murray
Hi Murray,
Thank for getting back and do you minde sharing any of those options?
Regards
Milan
 
Upvote 0
Hi Milan
For example, the post by bearcub at this thread would do exactly what you require. In your example the usage would be in B1
=DATESTAMP(A1)
It's not perfect because of the volatile nature of Now(), so take note of the caution in the original posting.

Regards

Murray
 
Upvote 0
Hi Milan
For example, the post by bearcub at this thread would do exactly what you require. In your example the usage would be in B1
=DATESTAMP(A1)
It's not perfect because of the volatile nature of Now(), so take note of the caution in the original posting.

Regards

Murray
Hi Murray
Thanks for the above. I found the code below works best for me.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1")) Is Nothing Then
If Len(Range("B1").Value) = 0 Then
Range("B1").Value = Now()
End If
End If
End Sub

In the above code, B1 will be autofill with the date if A1 is not blank, which works great.
However, I would like to apply this to a wide range, such as B1:B88, depending on the data entry in A1:A88.
For example, when data is entered in A25, then B25 is auto-filed with the date. My initial thought was that I could use the below code, but it did not work.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A88")) Is Nothing Then
If Len(Range("B1:B88").Value) = 0 Then
Range("B1:B88").Value = Now()
End If
End If
End Sub

I can repeat the initial code 88 times; however, I am sure there is a more efficient way to do it :)
Would you know how to adopt code for a broader range?

I apologize if it is a silly question; however, as you can see, I am still beginer with this

Thanks
Milan
 
Upvote 0
There are no silly questions - we all have to start somewhere. :)

You need to find out which row in column A the intersection occurred in, then make the change in column B in the same row.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRow As Variant
    If Not Application.Intersect(Target, Range("A1:A88")) Is Nothing Then
        MyRow = Intersect(Target, Range("A1:A88")).Row
        If Len(Range("B" & MyRow).Value) = 0 Then
            Range("B" & MyRow).Value = Now()
        End If
    End If
End Sub

Regards

Murray
 
Upvote 0
Solution
There are no silly questions - we all have to start somewhere. :)

You need to find out which row in column A the intersection occurred in, then make the change in column B in the same row.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRow As Variant
    If Not Application.Intersect(Target, Range("A1:A88")) Is Nothing Then
        MyRow = Intersect(Target, Range("A1:A88")).Row
        If Len(Range("B" & MyRow).Value) = 0 Then
            Range("B" & MyRow).Value = Now()
        End If
    End If
End Sub

Regards

Murray

Thank y
 
Upvote 0
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,621
Members
449,109
Latest member
Sebas8956

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