PDA

View Full Version : Error Handling Not Working



Ischyros
12-19-2008, 10:08 AM
I have some code that loops through and compares certain dates to the current date.

I get dates from a worksheet and then split them, the delimeter bing "/", and set the year, month, and day into a variant array.

The problems comes when, for example, somebody puts in "N/A" for the date and the variant array only has two values VariantVariable(0) and VariantVariable(1), so when I try to compare VariantVariable(2) to something I get a "subscript out of range error".

To circumven this I tried to use and ErrorHandler that just skips the date as shown in my code below. Any thoughts?

----
While j <= 23
On Error GoTo ByPass
date_str = Worksheets("Project List").Cells(i, j)
If Trim(date_str) <> "" Then
gdate = Split(date_str, "/")
'MsgBox (gdate(2) & " " & rdate(2))
If gdate(2) = rdate(2) Then
'Find place to put gate date
End If
Else
End If
Bypass:
j = j + 1
Wend
If Worksheets("3 Yr Schedule").Cells(k, 1) <> "" Then
k = k + 2
Else
End If
j = 21
i = i + 1
Wend
----------:think:

Bob Phillips
12-19-2008, 10:11 AM
You've go 2 Wends in there!

Bob Phillips
12-19-2008, 10:13 AM
Just test the date for IsError


If IsError(date_str) Then

'do one thing
Else

'do another
End If

Ischyros
12-19-2008, 10:42 AM
Thanks guys.....I cut the culprit off at the source and programmed an input mask!