I have the following code in sheet1 (note - this code is in the wroksheet object, not the workbook object or a module):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Integer
r = ActiveCell.Row
Cells(r - 1, 7).Value = Now()
ActiveWorkbook.save
End Sub
Can someone tell me why: 1. the ActiveWorkbook.save doesnt work above - it gets stuck in an infinite loop instead; 2. why I cant step throught the code by just pressing F8
I tried to put the ActiveWorkbook.save in a separate module and then call that function from the code in the worksheet but that got stuck in an infinite loop as well.
You need to disable events to avoid the infinite loop
Private Sub Worksheet_Change(ByVal Target As Range)
application.enableevents=false
Cells(target.row - 1, 7).Value = Now()
application.enableevents=true
ActiveWorkbook.save
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With