ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Statement (https://www.excelbanter.com/excel-programming/386857-if-statement.html)

Daviv

If Statement
 
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!

joel

If Statement
 
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



"Daviv" wrote:

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!


Tom Ogilvy

If Statement
 
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

--
Regards,
Tom Ogilvy


"Daviv" wrote:

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!



All times are GMT +1. The time now is 01:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com