Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 conditions in If...Then

Status
Not open for further replies.

pbellc

Programmer
Jun 6, 2003
36
US
Does anyone know how to put two conditions in an If...Then statement? It's not a ElseIf situation, I need both conditions to be true to complete the statement. Simply this is what I would like to do:

Dim i As Integer

i = 2
Do Until Worksheets("Data").Cells(i, 2).Value = Empty
i = i + 1

Loop

If Worksheets("Data").Cells(i, 1).Value =
Worksheets("Data2").Cells(i, 1).Value And
Worksheets("Data").cells(i,2).value = worksheets("data2").cells(i,2).value
THen
worksheets("data").cells(i,24)="yes"
Else
worksheets("data").cells(1,24)=""

End If
End Sub

THis doesn't work, and I think it has to do with the "AND" in there. What am I missing? Thanks all.
 
You're close, but there are a couple of problems.

1. You need to put an underscore at the end of a line that is continued to another line.

2. You need to put your code between the Do and the Loop
Code:
Sub test()
Dim i As Integer

i = 2
Do Until Worksheets("Data").Cells(i, 2).Value = Empty
i = i + 1


If Worksheets("Data").Cells(i, 1).Value =
[red]
Code:
 _
[/color]
Code:
    Worksheets("Data2").Cells(i, 1).Value And
[red]
Code:
 _
[/color]
Code:
    Worksheets("Data").Cells(i, 2).Value = Worksheets("data2").Cells(i, 2).Value
[red]
Code:
 _
[/color]
Code:
Then
    Worksheets("data").Cells(i, 24) = "yes"
Else
    Worksheets("data").Cells(1, 24) = ""

End If
[red]
Code:
Loop
[/color]
Code:
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top