tags:

views:

35

answers:

2

Hi again:)

I'm trying to understand this code, and I still don't know why it starts with 2 on the cell A1, shouldn't it start with 1?

Private Sub CommandButton1_Click()
Dim i, j As Integer
For i = 1 To 10
For j = 1 To 5
Cells(i, j).Value = i + j
Next j
Next i
End Sub

because on my other example I have this and it starts with 1 in A1:

  Private Sub CommandButton1_Click()
  Dim i As Integer
  For i = 1 To 10
  Cells(i, 1).Value = i
  Next
  End Sub

Thanks :-) will greatly appreciate your help

+1  A: 

At the first example you have two for-loops, one nested in another. You basically form a 2D array, with the value of each cell being the sum of the row and column index.

At the second example you have a 1D array.

kgiannakakis
ok, but why it starts with 2? did you try this on your end as well?
tintincute
+3  A: 

Both the loops in the first example starts with 1, so setting the value to i+j = 2.

In the second example it only sets it to i, which starts at 1.

astander