VBA Loop

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
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

[TABLE="width: 500"]
<tbody>[TR]
[TD]Apples[/TD]
[TD]3[/TD]
[TD]Apples &page=1&count=48[/TD]
[/TR]
[TR]
[TD]Pears[/TD]
[TD]2[/TD]
[TD]Apples &page=2&count=48[/TD]
[/TR]
[TR]
[TD]Apples[/TD]
[TD]2[/TD]
[TD]Apples &page=3&count=48[/TD]
[/TR]
[TR]
[TD]Grapes[/TD]
[TD]3[/TD]
[TD]Grapes &page=1&count=48[/TD]
[/TR]
[TR]
[TD]Apples[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bananas[/TD]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apples[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Pears[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Any help appreciated, thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Can you please explain what you are trying to do, as I cannot see any logic to your example?
 
Upvote 0
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:
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top