Results 1 to 5 of 5

Thread: VBA Loop
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Loop

    I have the following data in columns E and F.

    In G via a loop I am trying to populate - I have given a few examples in the right column as to how it should look. This attempt isn't quite working.

    Code:
    Sub Loop1()
    
    
    Dim i As Integer
    Dim j As Integer
    
    
    NumberRows = Application.WorksheetFunction.CountA(Columns("E:E"))
    
    
    For j = 1 To NumberRows
    
    
    For i = 1 To Cells(1, 6).Value
    
    
    Cells(j, 7) = (Cells(j, 5) & "&page=" & i & "&count=48")
    
    
    Next
    
    
    Next
    
    
    End Sub
    Apples 3 Apples &page=1&count=48
    Pears 2 Apples &page=2&count=48
    Apples 2 Apples &page=3&count=48
    Grapes 3 Grapes &page=1&count=48
    Apples 1
    Bananas 3
    Apples 1
    Pears 1

    Any help appreciated, thanks!

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,316
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: VBA Loop

    Can you please explain what you are trying to do, as I cannot see any logic to your example?
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    Feb 2010
    Location
    London, UK
    Posts
    9,298
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    3 Thread(s)

    Default Re: VBA Loop

    Try:
    Code:
    Sub m1()
    
        Dim LastRow   As Long
        Dim x         As Long
        Dim y         As Long
        Dim z         As Long: z = 1
        
        LastRow = Cells(Rows.Count, 5).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        For x = 1 To LastRow
            For y = 1 To Cells(x, 6).Value
                Cells(z, 7).Value = Cells(x, 5).Value & "&page=" & y & "&count=48"
                z = z + 1
            Next y
        Next x
        
        Application.ScreenUpdating = False
    
    End Sub
    Last edited by JackDanIce; Sep 9th, 2019 at 07:19 AM.


  4. #4
    Board Regular
    Join Date
    Sep 2014
    Posts
    629
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Loop

    Quote Originally Posted by JackDanIce View Post
    Try:
    Code:
    Sub m1()
    
        Dim LastRow   As Long
        Dim x         As Long
        Dim y         As Long
        Dim z         As Long: z = 1
        
        LastRow = Cells(Rows.Count, 5).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        For x = 1 To LastRow
            For y = 1 To Cells(x, 6).Value
                Cells(z, 7).Value = Cells(x, 5).Value & "&page=" & y & "&count=48"
                z = z + 1
            Next y
        Next x
        
        Application.ScreenUpdating = False
    
    End Sub
    JackDanIce that works thanks a lot!

  5. #5
    Board Regular
    Join Date
    Feb 2010
    Location
    London, UK
    Posts
    9,298
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    3 Thread(s)

    Default Re: VBA Loop

    You're welcome


Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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