monirg
Well-known Member
- Joined
- Jan 11, 2005
- Messages
- 629
Hello;
1) Please examine the following simple macro in a standard module:
It produces the error:
....."run-time error: '1004'
.....Application-defined or object-defined error"
with reference to the Worksheets statement.
2) By inserting "On Error Resume Next" before the Worksheets statement, there're no errors, and the macro and the entire algorithm appears to be working fine:
3) My concern is that the "On Error Resume Next" (which I don't often use) maybe telling VBA to ignore errors I didn't mean to ignore and I shouldn't, since I couldn't figure out why the Worksheets statement produced the run-time error in the first place!
Can someone please identify the cause of the problem, and whether it is "generally" safe to use "On Error Resume Next" when the cause of the error is not known (to me) ??
Thank you kindly.
1) Please examine the following simple macro in a standard module:
Code:
Sub UpdateNow()
If Range("j15") = "" Then Exit Sub
Worksheets("Burrill-et-al").Range("F1").Value = Format(Now, "hh:mm:ss") 'use any cell on the active w/s
Application.OnTime Now + TimeValue("00:00:01"), "UpdateNow"
End Sub
....."run-time error: '1004'
.....Application-defined or object-defined error"
with reference to the Worksheets statement.
2) By inserting "On Error Resume Next" before the Worksheets statement, there're no errors, and the macro and the entire algorithm appears to be working fine:
Code:
Sub UpdateNow()
On Error Resume Next
If Range("j15") = "" Then Exit Sub
Worksheets("Burrill-et-al").Range("F1").Value = Format(Now, "hh:mm:ss") 'use any cell on the active w/s
Application.OnTime Now + TimeValue("00:00:01"), "UpdateNow"
End Sub
Can someone please identify the cause of the problem, and whether it is "generally" safe to use "On Error Resume Next" when the cause of the error is not known (to me) ??
Thank you kindly.