Timestamp Macro
I appreciate both your responses. I was not in design mode (in fact, did not
even know it existed...but I do now). I made sure I was out. I tried the
breakpoint and it did not even act as if it go there.
So, maybe I have a fundamental issue. To install that code, I opened up
VBA, doubleclicked on the sheet I want the code in, and pasted that sub code
into the window, then hit save. I am in completely the wrong place? Is
there some other way that these events may be being shut off. Can't explain
it..it worked so well at first, then I was off merrily pretty-ing up my
worksheet, and came back to start adding data to the rows, and bang, it had
stopped working.
Frustated :-(
patk
"Gord Dibben" wrote:
Did it error out one time and leave events disabled?
In immediate window enter
Application.EnableEvents = True then hit Enter key.
If this was the cause, alter your code a bit to make sure events get turned
back on in the case of an error.
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
tr = t.Row
Set r = Range("A:Z")
If Intersect(t, r) Is Nothing Then Exit Sub
On Error GoTo endit 'add this
Set rr = Range("A" & tr & ":Z" & tr)
n = Application.WorksheetFunction.CountA(rr)
Debug.Print n
Application.EnableEvents = False
If n = 0 Then
Cells(tr, "AA").Clear
End If
If n = 1 Then
Cells(tr, "AA").Value = Now
End If
Cells(tr, "AB") = Now
endit: 'add this
Application.EnableEvents = True
End Sub
Gord Dibben MS Excel MVP
On Thu, 30 Oct 2008 15:48:06 -0700, PatK
wrote:
Hey, all....In another post in these forums, a gent had posted a really slick
macro to insert a timestamp in a row, if any cells in that row changed. I
"leveraged" that code (below). Problem is, it worked PERFECTLY for awhile,
and then completely stopped. I have inserted Debug code right at the top of
the subroutine, and it does not dump anything to the immediate window. I
have no idea why the macro worked so well, then stopped.
I have data in columns A through Z. My timestamp "was" going into column
AA, until it crapped out. Any ideas?
Thanks!,
PatK
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
tr = t.Row
Set r = Range("A:Z")
If Intersect(t, r) Is Nothing Then Exit Sub
Set rr = Range("A" & tr & ":Z" & tr)
n = Application.WorksheetFunction.CountA(rr)
Debug.Print n
Application.EnableEvents = False
If n = 0 Then
Cells(tr, "AA").Clear
End If
If n = 1 Then
Cells(tr, "AA").Value = Now
End If
Cells(tr, "AB") = Now
Application.EnableEvents = True
End Sub
|