If Statement

D

Daviv

In my worksheet, I have 2 columns and 3 rows. The 1st column is time; 2nd is
Weather. I want to write a procedure to check the completeness of the
report. For instance, if a time is filled out but the weather is not, the
message "Fill in Weather or Clear Time" appears. If nothing is filled out,
it is OK. Below is my code but it is not working. Thanks in advance.

Set STwo(0, 0) = .Range("O10")
Set STwo(1, 0) = .Range("O11")
Set STwo(2, 0) = .Range("O12")
STwo(3, 0) = "Fill in Weather or Clear Time."
Set STwo(0, 1) = .Range("Q10")
Set STwo(1, 1) = .Range("Q11")
Set STwo(2, 1) = .Range("Q12")
STwo(3, 1) = "Fill in Time or Clear Weather."


For i = 0 To 3
If STwo(i, 0) <> "" Then
ElseIf STwo(i, 1) <> "" Then
If STwo(i, 0) = "" Then
Application.Goto STwo(i, 1)
MsgBox STwo(3, 0)
Cancel = True
Exit Sub
ElseIf STwo(i, 1) = "" Then
Application.Goto STwo(i, 0)
MsgBox STwo(3, 1)
Cancel = True
Exit Sub
End If
End If
Next
Thanks!
 
J

Joel

Sub weather()
Dim STwo(3, 2)

With ActiveSheet
Set STwo(0, 0) = .Range("O10")
Set STwo(1, 0) = .Range("O11")
Set STwo(2, 0) = .Range("O12")
STwo(3, 0) = "Fill in Weather or Clear Time."
Set STwo(0, 1) = .Range("Q10")
Set STwo(1, 1) = .Range("Q11")
Set STwo(2, 1) = .Range("Q12")
STwo(3, 1) = "Fill in Time or Clear Weather."
End With


For i = 0 To 3
If STwo(i, 0) = "" Then
Application.Goto STwo(i, 0)
MsgBox STwo(3, 1)
Cancel = True
Exit Sub
End If
If STwo(i, 1) = "" Then
Application.Goto STwo(i, 1)
MsgBox STwo(3, 0)
Cancel = True
Exit Sub
End If
Next
End Sub
 
T

Tom Ogilvy

Set STwo(0, 0) = .Range("O10")
Set STwo(1, 0) = .Range("O11")
Set STwo(2, 0) = .Range("O12")
STwo(3, 0) = "Fill in Weather or Clear Time."
Set STwo(0, 1) = .Range("Q10")
Set STwo(1, 1) = .Range("Q11")
Set STwo(2, 1) = .Range("Q12")
STwo(3, 1) = "Fill in Time or Clear Weather."


For i = 0 To 2
If STwo(i, 0) <> "" and STwo(i,1) <> "" Then
ElseIf STwo(i, 0) = "" Then
Application.Goto STwo(i, 1)
MsgBox STwo(3, 0)
Cancel = True
Exit Sub
ElseIf STwo(i, 1) = "" Then
Application.Goto STwo(i, 0)
MsgBox STwo(3, 1)
Cancel = True
Exit Sub
End If
Next
 

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