Multiple Worksheet_Change

sr7

New Member
Joined
Nov 16, 2021
Messages
4
HEllo, I am trying to build two timestamps in the same row that trigger from different cell changes.
When column B changes, timestamp in column F
When Column L changes, Timestamp in column M

My second timestamp wont work. any ideas? Heres my code:


VBA Code:
'timestamps

Private Sub Worksheet_Change(ByVal Target As Range)
Call EventChange_1(Target)
Call EventChange_2(Target)
End Sub


'assign timestamp

Sub EventChange_1(Target)
Dim F As Range, B As Range, t As Range

Set F = Range("F:F")
Set B = Range("B:B")
Set t = Target

If Intersect(t, B) Is Nothing Then Exit Sub

Application.EnableEvents = False
Range("F" & t.Row).Value = Now
Application.EnableEvents = True
End Sub

'Complete timestamp
Sub EventChange_2(Target)
Dim M As Range, L As Range, t As Range

Set M = Range("M:M")
Set L = Range("L:L")
Set t = Target

If Intersect(t, L) Is Nothing Then Exit Sub

Application.EnableEvents = False
Range("M" & t.Row).Value = Now
Application.EnableEvents = True
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,400
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Forum!

My second timestamp wont work. any ideas? Heres my code:

Your code "works" for me, in the sense that it behaves exactly as I'd expect.

Can you please provide more detail? When you say the code doesn't work, what cell changes are you making?
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
18,233
Office Version
  1. 2013
Platform
  1. Windows
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  11/16/2021  9:24:54 PM  EST
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

    Select Case Target.Column
        Case 2
            Target(, 5).Value = Now
        Case 12
            Target(, 2).Value = Now
    End Select
End Sub
 

sr7

New Member
Joined
Nov 16, 2021
Messages
4
Welcome to the Forum!



Your code "works" for me, in the sense that it behaves exactly as I'd expect.

Can you please provide more detail? When you say the code doesn't work, what cell changes are you making?
Thanks for the Welcome and for looking at this. it seems to be working now!
Welcome to the Forum!



Your code "works" for me, in the sense that it behaves exactly as I'd expect.

Can you please provide more detail? When you say the code doesn't work, what cell changes are you making?
 

StephenCrump

MrExcel MVP
Joined
Sep 18, 2013
Messages
4,400
Office Version
  1. 365
Platform
  1. Windows
it seems to be working now!
That's good to hear, thanks.

@My Aswer Is This has provided more succinct code you also might like to try. At the moment, it's set up to deal with only cell changing at a time, but this can easily be changed to more than one row/column if you envisage the user changing multiple cells at once and you want to time-stamp all relevant cells?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,972
Messages
5,767,402
Members
425,410
Latest member
SmittyT

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
Top