Stop UDF/code from updating time when cell is edited

buttergoose

New Member
Joined
Dec 19, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi!
I've found great help in this forum, but now I need help I couldn't find in existing threads.

I have used this code, to generate an automatic time and date in an excel sheet my work uses for logging activity. Very simple; event text goes in column G, date generates per auto in column A and C.
Now, question;
When I fill an event, and trigger the auto fill for date and time, how can I stop the date/time cells from updating if I come back later and edit the text in column G (and hence prompting a new auto update with current date/time)? I only need one static entry of date and time for when the event text was entered, and then I want it to not change at all.

This is the code I've used and it works splendid for everything a part from this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Columns("G")) Is Nothing Then
If Target.Row > 1 And Target.Offset(, 2) = "" Then
Target.Offset(, -6) = Date
Target.Offset(, -5) = Time
End If
End If
End If
End Sub


Suggestion on what to add/change to get where I wanna be?

Many thanks!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the forum, you could try the below:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count = 1 Then
        If Not Intersect(Target, Columns("G")) Is Nothing Then
            If Target.Row > 1 And Target.Offset(, 2) = "" Then
                If Target.Offset(, -6) = "" Then
                    Target.Offset(, -6) = Date
                    Target.Offset(, -5) = Time
                End If
            End If
        End If
    End If
End Sub
 
Upvote 0
Solution
Welcome to the forum, you could try the below:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count = 1 Then
        If Not Intersect(Target, Columns("G")) Is Nothing Then
            If Target.Row > 1 And Target.Offset(, 2) = "" Then
                If Target.Offset(, -6) = "" Then
                    Target.Offset(, -6) = Date
                    Target.Offset(, -5) = Time
                End If
            End If
        End If
    End If
End Sub
Thank you!
I tried copy pasting your code to my sheet but the time (and date surely, but that of course won't change every second haha) is still updating if I change the previously filled G column text...
 
Upvote 0
Thank you!
I tried copy pasting your code to my sheet but the time (and date surely, but that of course won't change every second haha) is still updating if I change the previously filled G column text...
To add to this, my guess would be that I need some type of code string that checks if the date and time cells are filled, and if they are then to not mess with them at all... I just don't know how to do that specifically
 
Upvote 0
As 'Target.Offset(, -6) = Date' is placing the date in the cell the is offset -6 columns from target.

This row:
VBA Code:
If Target.Offset(, -6) = "" Then
Will check to see if there is already something in the date cell, if there is then it will not update the date and time.

Check the code you have used because I edited my post about one minute after I posted because I used '<>' instead of '=' by mistake in my original post.
 
Upvote 0
As 'Target.Offset(, -6) = Date' is placing the date in the cell the is offset -6 columns from target.

This row:
VBA Code:
If Target.Offset(, -6) = "" Then
Will check to see if there is already something in the date cell, if there is then it will not update the date and time.

Check the code you have used because I edited my post about one minute after I posted because I used '<>' instead of '=' by mistake in my original post.
I didn't catch that <> either haha

Thank you so much, it's doing what I want it to now.
Greatly appreciated!
 
Upvote 0
You're welcome, thanks for the feedback.

Silly mistake from me...
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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