PDA

View Full Version : The triple loop....



DevanG
06-10-2011, 10:50 AM
here we go... idk where my problem is... i don't really get the VBA debugs..
It points to my wbook.Sheets(1).Range("H" & j).Copy Workbooks(Name).Sheets(1).Cell(i, 22 + l) as not having a supported method...

after that.. please try to see what else is wrong with my loops..

' comparing contract numbers and inserting log numbers into summary
For i = 5 To 100 ' summary contracts
For j = 2 To 100 ' report contracts
If Workbooks(Name).Sheets(1).Range("B" & i).Value = wbook.Sheets(1).Range("A" & j).Value Then
For l = 1 To 100 ' find open log # pasting area
If Workbooks(Name).Sheets(1).Cells(i, 22 + l) = "" Then
wbook.Sheets(1).Range("H" & j).Copy Workbooks(Name).Sheets(1).Cell(i, 22 + l)
End If
Next l
i = i - 1 'to check for multiple logs
j = j + 1
GoTo P2
Else
If wbook.Sheets(1).Range("A" & j).Value = 0 Then 'to check if at end of report
GoTo P3
End If
End If
Next j
P3: If Workbooks(Name).Sheets(1).Range("B" & (i + 1)).Value = 0 Then 'to check if at end of summary
GoTo P4
End If
P2: Next i
P4:

Kenneth Hobs
06-10-2011, 11:32 AM
Welcome to the forum! Please use VBA code tags around your pasted code.

It is not good practice to use variable names to be the same a reserved names for methods and properties. So, what is the value of Name in Worsheets(Name)?

Tip: Always use Option Explicit as the first line in your Module.