Consulting

Results 1 to 2 of 2

Thread: The triple loop....

  1. #1
    VBAX Regular
    Joined
    Jun 2011
    Posts
    28
    Location

    The triple loop....

    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..

    [VBA]' 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:[/VBA]
    Last edited by Bob Phillips; 06-10-2011 at 10:37 PM. Reason: Added VBA Tags

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •