Reputation: 55
I am trying to do a multiple condition search. If two parameters are equal to another two parameters in another worksheet, then do something.
The inner Do While
runs once.
Sub main()
Dim mat As String
Dim sp As String
Dim colArt As Integer
colArt = 8
Dim colMat As Integer
colMat = 2
Sheets("Art.1 (2)").Activate
Dim i As Integer
i = 5
Dim j As Integer
j = 2 'Row
Do While i < 12
If (Cells(i, colArt) <> "") Then
Dim tempMat As String
tempMat = Cells(i, colArt)
Dim tempSp As Integer
tempSp = Cells(i, colArt - 1)
Do While j < 16
If (Worksheets("Mat").Cells(j, colMat) <> "") Then
Dim tempMatMat As String
tempMatMat = Worksheets("Mat").Cells(j, colMat)
If (StrComp(tempMat, tempMatMat, vbTextCompare) = 0) Then
MsgBox (tempMatMat)
End If
End If
j = j + 1
Loop
End If
i = i + 1
Loop
End Sub
Upvotes: 0
Views: 179
Reputation: 7409
Federico, you need to reset j
each time you loop in the outer loop:
Do While i < 12
j = 2
If (Cells(i, colArt) <> "") Then
Dim tempMat As String
tempMat = Cells(i, colArt)
Upvotes: 2