Help with VBA

jmazorra

Well-known Member
Joined
Mar 19, 2011
Messages
715
Hello everyone:

I was helped earliear by a couple of experts on date stamp. I was referred to a site to find the resources. The site used the code:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count > 1 Then Exit Sub
If Not Intersect(Range("e19:e32"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub [code/]
 
The problem is that cell e19:32 get their value from a formula. With this code it only works if I press enter after entering the value in one of the referencing cells. E19:E32 are dynamic cells that change based on formulas so the code needs to work on change not enter.
 
Any help?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
try using
Private Sub Worksheet_calculate instead of

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Be warned however that this will probably make your spreadsheet slow, the code will be run, atevey calculation.
 
Upvote 0
If all of the cell references in those formula as all located on the same worksheet as the formulas themselves, then you can use this variation on the code that you posted...

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
  With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(Range("e19:e32").Precedents, .Cells) Is Nothing Then
    Application.EnableEvents = False
    If IsEmpty(.Value) Then
      .Offset(0, 1).ClearContents
    Else
      With .Offset(0, 1)
        .NumberFormat = "dd mmm yyyy hh:mm:ss"
        .Value = Now
      End With
    End If
    Application.EnableEvents = True
    End If
  End With
End Sub
Note that the only change I made is to add the .Precedents to your Range("e19:e32") reference inside the Intersect function call.
 
Upvote 0
Thanks, I tried the code, but it still did not work. my cell only populates when I press enter, not when value changes
 
Upvote 0

Forum statistics

Threads
1,217,083
Messages
6,134,467
Members
449,873
Latest member
andikadwi

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