Advanced loop

Stevenn

Active Member
Joined
Feb 8, 2012
Messages
259
I am trying to make a loop which loops a total of 20 times with following output based on the two variables limit_x = 3 and limit_y = 4:

x
y
00
01
02
03
04
10
11
12
13
14
20
21
22
23
24
30
31
32
33
34

<colgroup><col style="width:48pt" span="2" width="64"> </colgroup><tbody>
</tbody>

In other words, I want to go through 5 y's for 4 x's looping from 0 to 4 and 0 to 3 respectively. I hope it's understandable :)

Can anyone help me to write the loop?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try

Code:
Sub test()
Dim x As Long, y As Long, i As Long
For x = 0 To 3
    For y = 0 To 4
        i = i + 1
        Range("A" & i).Value = x
        Range("B" & i).Value = y
    Next y
Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,360
Messages
6,130,175
Members
449,562
Latest member
mthrasher16

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