+ Reply to Thread
Results 1 to 3 of 3

Can't get nested Loop to copy range values from 2 tables working correctly

Hybrid View

gtol Can't get nested Loop to copy... 04-05-2013, 11:23 AM
StephenR Re: Can't get nested Loop to... 04-05-2013, 11:41 AM
gtol Re: Can't get nested Loop to... 04-05-2013, 12:01 PM
  1. #1
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can't get nested Loop to copy range values from 2 tables working correctly

    Using your framework:
    Sub TestLoop()
    
       Dim Ws1 As Worksheet
       Dim Ws2 As Worksheet
          
       Dim Depts As Range
       Dim Roles As Range
       
       Dim CurCell As Range
       Dim DestCell As Range
        
       Dim i As Integer
       Dim j As Long
       Dim k As Long
       Dim NumRows As Integer
             
             
       Set Ws1 = Worksheets("Source")
       Set Ws2 = Worksheets("Destination")
       Set Depts = Range("Departments")
       Set Roles = Range("Roles")
             
       
       Set DestCell = Range("B6")
       NumRows = Depts.Rows.Count
       
       
       Application.ScreenUpdating = False
              
      'starting position
        
        For i = 1 To NumRows
            For j = 1 To Roles.Count
                Ws2.Range("A1").Offset(k) = Depts(i)
                Ws2.Range("A1").Offset(k, 1) = Roles(j)
                k = k + 1
            Next j
        Next i
        
       Application.ScreenUpdating = True
           
    End Sub

  2. #2
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Can't get nested Loop to copy range values from 2 tables working correctly

    Hi StephenR from London

    What can I say ???
    That works perfectly and I can apply this to my application.
    Very neat and tidy code indeed.

    Thanks a million !!!


    GTOL

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1