Multiple Loops in Excel Vba

In this article we are going to learn how to use multiple loops in VBA. We are going to use the For Next Loop.

Adding command button

To add a command button click on "Insert" and then select "Command Button" from ActiveX group.

Multiple Loops insert command button

Create a command button.

Multiple Loops create command button

Write click on the command button and Select "View Code".

Multiple Loops select view code

Nesting Vba Loops

Write this line of code. After writing the code, close the window by clicking on the red X button on the top left of the screen.

Dim i As Integer, j As Integer
For i=1 To 1 to 6 For j=1 To 2 Cells (i, j).Value=100 Next j Next i
End Sub

Multiple Loops vba code

Click on the command button to see this result.

Multiple Loops click command button

That’s it! This is how to implement two for loops using Excel VBA.