How to know if cell value really changed?

dma431

Board Regular
Joined
Jul 16, 2017
Messages
82
Hello,

I'm using very simple code to add the current date to a cell when the adjacent cell was modified.
It works well, except when you select the value and click the formula bar, without making any changes to the actual value, then click on some other cell.
When that happens, it assumes the value changed, and refreshes the date next to it.

I was wondering if there's a way to check if the value remained the same after clicking away, and if it did, keep the date value intact.

Here's the code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
    If Cell.Column = Range("C:C").Column Then
        If Cell.Value <> "" Then
            Cells(Cell.Row, "D").Value = Now
        Else
            Cells(Cell.Row, "D").Value = ""
        End If
    End If
Next Cell
End Sub

Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Are you changing multiple cells at once, or just one by one?
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim CurrentValue As Variant, OldValue As Variant
   
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C:C")) Is Nothing Then
      If Target.Value = "" Then
         Target.Offset(, 1).Value = ""
      Else
         CurrentValue = Target.Value
         With Application
            .EnableEvents = False
            .Undo
            If Target.Value <> CurrentValue Then
               Target.Value = CurrentValue
               Target.Offset(, 1).Value = Now
            End If
            .EnableEvents = True
         End With
      End If
   End If
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
Hi, I am riding on this thread as I have a similar challenge.
I am doing a sales funnel, where I have a dropdown list of stages in column G, and any changes are reflected in column H.
The problem I have is whenever someone clicks on the individual cell but did not make any changes (e.g. click on a cell titled "prospect", but choose "prospect" from the list), the date would automatically update itself.

1624451964227.png


How do I amend the following code so that there will only be a change in date if the value in the cell changes (e.g. from prospect to qualify)? Any advice?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("G:G"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Please start a thread of your own for this question. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,052
Members
448,940
Latest member
mdusw

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