handling error in IF ELSEIF statement

S

Sabosis

Hello-

I have the following code that checks 3 scenarios in an IF statement,
and sends an email to a select group if the conditions are true.

If Workbooks("Sr Rep Stats").Worksheets("Combined").Range("d4").Value
0.03 Then
Call CentreVuSeniorA
ElseIf Workbooks("Sr Rep Stats").Worksheets("Combined").Range
("d3").Value > 0.03 Then
Call CentreVuSeniorB
ElseIf Workbooks("Sr Rep Stats").Worksheets("Combined").Range
("d2").Value > 0.03 Then
Call CentreVuSeniorC
Else
End If
Application.DisplayAlerts = False
Application.Quit

"d4" is a combined number for city A & city B, "d3" is city A, and
"d2" is city B. The problem I am having is that this code starts
running at 7:00 am via task scheduler, and there are times that "d3"
might show #DIV/0! as it is a calculated cell and there might not be
statistics for city A at 7:00am.

I tried to add a bit of code to this line to only look at the 2nd IF
statement when the time is greater than 7:00 AM, but it did not work:

If Workbooks("Sr Rep Stats").Worksheets("Combined").Range("d3").Value
0.03 And Time > TimeSerial(7, 0, 0) Then
Call CenrteVuSeniorB

Any ideas?

Thanks
 
S

smartin

Sabosis said:
Hello-

I have the following code that checks 3 scenarios in an IF statement,
and sends an email to a select group if the conditions are true.

If Workbooks("Sr Rep Stats").Worksheets("Combined").Range("d4").Value
Call CentreVuSeniorA
ElseIf Workbooks("Sr Rep Stats").Worksheets("Combined").Range
("d3").Value > 0.03 Then
Call CentreVuSeniorB
ElseIf Workbooks("Sr Rep Stats").Worksheets("Combined").Range
("d2").Value > 0.03 Then
Call CentreVuSeniorC
Else
End If
Application.DisplayAlerts = False
Application.Quit

"d4" is a combined number for city A & city B, "d3" is city A, and
"d2" is city B. The problem I am having is that this code starts
running at 7:00 am via task scheduler, and there are times that "d3"
might show #DIV/0! as it is a calculated cell and there might not be
statistics for city A at 7:00am.

I tried to add a bit of code to this line to only look at the 2nd IF
statement when the time is greater than 7:00 AM, but it did not work:

If Workbooks("Sr Rep Stats").Worksheets("Combined").Range("d3").Value
Call CenrteVuSeniorB

Any ideas?

Thanks

Not totally sure I understand the problem. If you want to avoid
processing the Call when the target cell has an error in it you can
check for that first:

debug.print iserror(range("d3")) ' true when d3 has #DIV/0!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top