2017-07-03 5 views
0

複数条件検索を実行しようとしています。 2つのパラメータが別のワークシートの別の2つのパラメータと等しい場合は、何かを実行します。ネストされたDo内側ループは外側ループの最初の繰り返しでのみ実行されます。

Do Whileは1回実行されます。

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 
+1

'0' 'にリセットする必要がj'後/他の内部ループラウンド2回目の前にその値は 'while'条件を満たしません。 –

答えて

2

フェデリコは、あなたがjを毎回リセットする必要があります外側のループのループ:

Do While i < 12 
    j = 2 
    If (Cells(i, colArt) <> "") Then 
     Dim tempMat As String 
     tempMat = Cells(i, colArt) 
+0

ありがとう!少し残って、didntがああ参照してください –

+0

あなたは大歓迎です。見逃しやすい。 do-whileループが動作するときはいつでも**これは目を引くものです。 – TomServo

関連する問題