montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 984
- Office Version
- 2010
- Platform
- Windows
Hello, Fox, Hope you SAFE.
Formula.Average
The same formula must be entered in the
successive cells in a worksheet columns, but
One of the references, in the formula must be
incremente, by more than one row.
The spreadsheet contains 48 blocks of data,
in columns (“A:D”).
(“For illustration purpose I am showing 3 only”)
Each block is separated by four rows.
The average of each column
in the data block
Is to be calculated and entered
in the first 4 rows of columns (“F:I”).
Thus, the formula strings for rows 2 and 3 in column F must be
“=AVERAGE(A2:A6)” And
“AVERAGE(A11:A15)”, respectively
the reference to the
row index in
these formulas
increases by 9, but the
Difference in the cells that hold the formulas
is only 1.
Therefore,
the correct formula for cell F3
cannot be obtained with a
copy and paste of cell F2 Because the
difference between the
row indices in
successive formulas is a constant.
But when I tried
a Variable -> J <- for the outer loop
do not work.
And the real data is for the whole year
48 weeks (or blocks).
Formula.Average
The same formula must be entered in the
successive cells in a worksheet columns, but
One of the references, in the formula must be
incremente, by more than one row.
The spreadsheet contains 48 blocks of data,
in columns (“A:D”).
(“For illustration purpose I am showing 3 only”)
Each block is separated by four rows.
The average of each column
in the data block
Is to be calculated and entered
in the first 4 rows of columns (“F:I”).
Thus, the formula strings for rows 2 and 3 in column F must be
“=AVERAGE(A2:A6)” And
“AVERAGE(A11:A15)”, respectively
the reference to the
row index in
these formulas
increases by 9, but the
Difference in the cells that hold the formulas
is only 1.
Therefore,
the correct formula for cell F3
cannot be obtained with a
copy and paste of cell F2 Because the
difference between the
row indices in
successive formulas is a constant.
But when I tried
a Variable -> J <- for the outer loop
do not work.
And the real data is for the whole year
48 weeks (or blocks).
VBA Code:
Sub Montecarlo_avr()
Dim i As Integer
For i = 0 To 2
Cells(i + 2, 6).Formula = "=Average(A" & (i + 2) + (i * 8) & ":A" & (i + 6) + (i * 8) & ")"
Cells(i + 2, 7).Formula = "=Average(B" & (i + 2) + (i * 8) & ":B" & (i + 6) + (i * 8) & ")"
Cells(i + 2, 8).Formula = "=Average(C" & (i + 2) + (i * 8) & ":C" & (i + 6) + (i * 8) & ")"
Cells(i + 2, 9).Formula = "=Average(D" & (i + 2) + (i * 8) & ":D" & (i + 6) + (i * 8) & ")"
Next i
End Sub