Auto Input Date When Cell Text Is First Added (1 Viewer)

dawsonrhodes

Member
Local time
Today, 05:46
Joined
Mar 8, 2020
Messages
85
Hello,

I am trying to use VBA to create an automatic date entry when the feilds in B:B are first added. This will be recorded in the adjacent A column.

I'd like each seperate row to record the date, which I'll use for a calculation between the two dates (in A and in B columns)

I would prefer it does not update in the case the B column is updated, I want the value in the A column to record one, and once only.

Not sure if this is possible. In the below example, I included a visual.

Thank you in advance for any help!


1630541598003.png
 

Sun_Force

Active member
Local time
Today, 18:46
Joined
Aug 29, 2020
Messages
396
Not sure if this is possible. In the below example, I included a visual.
Everything is possible. I'm not sure if this is the best solution and I'm also sure someone will come out with a better and less code, but for now test the attached file.

Of course you need to add some code with different situation and also error trapping, but it will give you the idea. You also need to add some code for when you delete a cell in column B.
I have a test in less than an hour and couldn't finished it.

I'm not sure how much you know about vba, but you have either put the file in a trusted location to allow running vba code, or you must accept the msgbox you receive when you open the file for the first time.
 

Attachments

  • Book2.zip
    12.8 KB · Views: 141
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:46
Joined
May 7, 2009
Messages
19,234
on VBA, click on the sheet on the Project explorer and paste this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        If Len(Target.Offset(0, -1) & "") = 0 And Target.Row > 5 Then
            Target.Offset(0, -1) = Date
        End If
    End If
End Sub
 

dawsonrhodes

Member
Local time
Today, 05:46
Joined
Mar 8, 2020
Messages
85
on VBA, click on the sheet on the Project explorer and paste this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        If Len(Target.Offset(0, -1) & "") = 0 And Target.Row > 5 Then
            Target.Offset(0, -1) = Date
        End If
    End If
End Sub
Works like a charm, thank you!
 

Users who are viewing this thread

Top Bottom