Double Loop
You can use a double loop to loop through a two-dimensional range of cells.
Place a command button on your worksheet and add the following code lines:
Dim i As Integer, j As Integer
For i = 1 To 6
For j = 1 To 2
Cells(i, j).Value = 100
Next j
Next i
Result when you click the command button on the sheet:
Explanation: For i = 1 and j = 1, Excel VBA enters the value 100 into the cell at the
intersection of row 1 and column 1. When Excel VBA reaches Next j, it increases j
with 1 and jumps back to the For j statement. For i = 1 and j = 2, Excel VBA enters
the value 100 into the cell at the intersection of row 1 and column 2. Next, Excel
VBA ignores Next j because j only runs from 1 to 2. When Excel VBA reaches Next
i, it increases i with 1 and jumps back to the For i statement. For i = 2 and j = 1, Excel
VBA enters the value 100 into the cell at the intersection of row 2 and column 1, etc.