robertsa123
03-06-2013, 09:08 AM
Hi,
I am trying to run a sub-routine that will fill in the values of row numbers over 10 columns and 20 rows. I want the first value of the second column to be the last value of the previous column +1, as seen below
1 21
2 22
3 23
4 24
5 25
6 26
7 27
8 28
9 29
10 30
11 31
12 32
13 33
14 34
15 35
16 36
17 37
18 38
19 39
20 40
Here is the code i've been using so far:-
Sub sForLoop5()
Dim iCol As Integer
Dim iRow As Integer
Dim iFirstCol As Integer: iFirstCol = 1
Dim iLastCol As Integer: iLastCol = 10
Dim iFirstRow As Integer: iFirstRow = 1
Dim iLastRow As Integer: iLastRow = 20
For iCol = iFirstCol To iLastCol
For iRow = iFirstRow To iLastRow
Cells(iRow, iCol).Value = iRow
Next iRow
Next iCol
End Sub
I am not sure what to put in the value part to get the next column to add 1 to the previous column's last value. If anyone can help that'd be great!
Adam
I am trying to run a sub-routine that will fill in the values of row numbers over 10 columns and 20 rows. I want the first value of the second column to be the last value of the previous column +1, as seen below
1 21
2 22
3 23
4 24
5 25
6 26
7 27
8 28
9 29
10 30
11 31
12 32
13 33
14 34
15 35
16 36
17 37
18 38
19 39
20 40
Here is the code i've been using so far:-
Sub sForLoop5()
Dim iCol As Integer
Dim iRow As Integer
Dim iFirstCol As Integer: iFirstCol = 1
Dim iLastCol As Integer: iLastCol = 10
Dim iFirstRow As Integer: iFirstRow = 1
Dim iLastRow As Integer: iLastRow = 20
For iCol = iFirstCol To iLastCol
For iRow = iFirstRow To iLastRow
Cells(iRow, iCol).Value = iRow
Next iRow
Next iCol
End Sub
I am not sure what to put in the value part to get the next column to add 1 to the previous column's last value. If anyone can help that'd be great!
Adam