user2504394
user2504394

Reputation: 41

Loop without do

I'm trying to create a do while nested loop but it gives me the error

Loop without do

Why?

Sub Copia_e_completa()
'Identifico ultima riga che ha un valore
Dim UltimaCellaFoglio1
Dim UltimaCellaFoglio2
UltimaCellaFoglio1 = (Sheets("Foglio1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
UltimaCellaFoglio2 = (Sheets("Foglio2").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
Dim I As Integer
Dim articolo1 As String
Dim cliente1 As String
Dim articolo2 As String
Dim cliente2 As String
I = 2
Do While I <= UltimaCellaFoglio1
MsgBox (I)
articolo1 = (Worksheets("Foglio1").Cells(I, 1).Value)
cliente1 = (Worksheets("Foglio1").Cells(I, 4).Value)
I = I + 1
    Dim J As Integer
    Do While J <= UltimaCellaFoglio2
     articolo2 = (Worksheets("Foglio2").Cells(J, 1).Value)
     cliente2 = (Worksheets("Foglio2").Cells(J, 2).Value)
     If (articolo1 = articolo2) And (cliente1 = cliente2) Then
     Worksheets("destinazione1").Range("A" & I, "M" & I).Value = Worksheets("Foglio1").Range("A" & I, "M" & I).Value
     Worksheets("destinazione1").Range("N" & I, "Y" & I).Value = Worksheets("Foglio2").Range("D" & J, "Y" & J).Value
     Else
      J = J + 1
    Loop
Loop

End Sub

Upvotes: 0

Views: 6383

Answers (1)

Bathsheba
Bathsheba

Reputation: 234645

You're missing an End If just after the line J = J + 1

Upvotes: 3

Related Questions