keep date today without change when date is today

Hasson

Active Member
Joined
Apr 8, 2021
Messages
391
Office Version
  1. 2016
Platform
  1. Windows
Hi expert

here is the code when the column C contains DONE word , then will populate date (today) for adjacent cells for column D . my problem the date will change if I press inside the cells into column C without change word . it should keep old date without change date .
for instance :
cells in column D contain DONE word and date 02/12/2023
and tomorrow should keep DONE word and date 02/12/2023 without any change , but if I try changing NOT YET word to DONE word , then should populate date (today).

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Me.Range("C14:C200")) Is Nothing Then
        Dim cell As Range
        For Each cell In Application.Intersect(Target, Me.Range("C14:C200"))
            If cell.Value = "DONE" Then
                cell.Offset(0, 1).Value = Date
            ElseIf cell.Value = "NOT YET" Then
                cell.Offset(0, 1).ClearContents
            End If
        Next cell
      
    End If

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi,

You could test following
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("C14:C200")) Is Nothing Then Exit Sub
    With Target
        If .Value = "DONE" Then
            .Offset(0, 1).Value = Date
            .Offset(0, 1).Value = .Offset(0, 1).Value
        ElseIf .Value = "NOT YET" Then
            .Offset(0, 1).ClearContents
        End If
    End If
End Sub
 
Upvote 0
thanks
there is no difference with comparison the original code, sorry !
and you have typo .you should clear END IF in the end code and replace with END WITH
 
Upvote 0
Good you could spot the typo .. Sorry....:(

But have you spotted the difference ...? (hint : 6th line)

Have you tested it ???
 
Upvote 0
But have you spotted the difference ...? (hint : 6th line)
that's why there is no difference , it continues populating Date (today)
have you check your mistake?
Have you tested it ???
yes I changed regional setting for date in my laptop to see how works.
based on (hint : 6th line) logically continues populating date(today) because of from the base depends on date(today) this is what I think .;)
 
Upvote 0
You could test following
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("C14:C200")) Is Nothing Then Exit Sub
    With Target
        If UCase(.Value) = "DONE" And Not IsEmpty(.Offset(0, 1)) Then Exit Sub
        If UCase(.Value) = "NOT YET" Or IsEmpty(.Value) Then
            .Offset(0, 1).ClearContents
        ElseIf UCase(.Value) = "DONE" Then
            .Offset(0, 1) = Date
        End If
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,824
Messages
6,127,092
Members
449,358
Latest member
Snowinx

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