I have a function that does some stuff to a bunch of cells every 15 seconds.
EventMacro is called when the workbook in question is opened.
The script does its job great on the workbook its supposed to run on.
But the problem is this: if I have the book with this script open, then hit ctrl+n and open a new workbook, I suddenly get a "subscript out of range error" from my updateDates function. Whats causing this? why does my macro want to run on other sheets?
Thanks for the advice.
Sub EventMacro()
Call updateDates
alertTime = Now + TimeValue("00:00:15")
Application.OnTime alertTime, "EventMacro"
End Sub
Private Sub updateDates()
Dim ws As Worksheet
Set ws = Worksheets("Data")
If Not (ws Is Nothing) Then
For Counter = 10 To 1000
If (IsEmpty(ws.Cells(Counter, 2).Value)) Then 'if no date entered
If Not IsEmpty(ws.Cells(Counter, 4)) Then 'and a value is in the cell
ws.Cells(Counter, 2).Value = Now 'enter today's date
Else
GoTo last 'stops the script from running too far, if both date and data are blank skip out of the loop
End If
End If
Next Counter
End If
last:
End Sub
Bookmarks