+ Reply to Thread
Results 1 to 5 of 5

Help with nested loops

Hybrid View

wishmaker Help with nested loops 04-10-2013, 05:40 AM
Norie The description and the code... 04-10-2013, 05:58 AM
wishmaker Re: Help with nested loops 04-10-2013, 07:35 AM
wishmaker Re: Help with nested loops 04-23-2013, 10:41 AM
Norie Re: Help with nested loops 04-23-2013, 11:03 AM
  1. #1
    Registered User
    Join Date
    11-12-2009
    Location
    surrey
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Help with nested loops

    Please find sample file attached

    Regards
    John

    John_Budgets to be imported.xlsm

  2. #2
    Registered User
    Join Date
    11-12-2009
    Location
    surrey
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Help with nested loops

    Solved the problem but it runs a bit slow...

     Dim MyLastRow As Integer, i As Integer
    Dim x As Long, y As Long, j As Long, k As Long
    Dim BGTree As Long
    Dim BGName As String, RG As String, DateFrom As String, DateTo As String
    Dim PeriodDate As String, Period As String, Balance As String, AccountCode As String
    Dim sWBU As Worksheet, sWBUT As Worksheet
    
    i = 16  'Which column in data sheet is the first Balance/AccountCode
    j = 2   'Which row in new sheet to start at
    k = 53  'Which row in new sheet to stop at
    
    Set sWBU = Worksheets("Wish Budg To Be uploaded") ' Name of worksheets for data source
    Set sWBUT = Worksheets("Upload Data") ' Name of worksheets for data destination
    MyLastRow = sWBU.Cells(Application.Rows.Count, 2).End(xlUp).Row 'Find Final Row in dataset
    
    For y = 12 To MyLastRow '(y) Equates to row 12 of the first row of the source data
            For x = j To k
            BGTree = sWBU.Cells(y, 4).Value
            BGName = sWBU.Cells(y, 12).Value
            DateFrom = sWBU.Cells(y, 6).Value
            DateTo = sWBU.Cells(y, 7).Value
            PeriodDate = sWBU.Cells(y, 5).Value
            Period = sWBU.Cells(y, 8).Value
            Balance = sWBU.Cells(y, i).Value
            AccountCode = sWBU.Cells(7, i).Value
            sWBUT.Cells(x, 1).Value = BGTree
            sWBUT.Cells(x, 2).Value = BGName
            sWBUT.Cells(x, 3).Value = BGTree
            sWBUT.Cells(x, 4).Value = BGTree
            sWBUT.Cells(x, 5).Value = BGTree
            sWBUT.Cells(x, 6).Value = BGTree
            sWBUT.Cells(x, 7).Value = BGTree
            sWBUT.Cells(x, 8).Value = BGName
            sWBUT.Cells(x, 9).Value = "Range"
            sWBUT.Cells(x, 11).Value = DateFrom
            sWBUT.Cells(x, 12).Value = DateTo
            sWBUT.Cells(x, 13).Value = PeriodDate
            sWBUT.Cells(x, 14).Value = Period
            sWBUT.Cells(x, 15).Value = Balance
            sWBUT.Cells(x, 16).Value = AccountCode
            sWBUT.Cells(x, 17).Value = Balance
           i = i + 1
            Next x
        j = j + 52
        k = k + 52
        i = 16
    Next y

+ 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