Ellis,
the problem is that because everything in the expression
Code
-------------------
"=Average(Cells(n, 1), Cells(n, 2))
-------------------
is between quotes it is put into the cell as is.
If you would want the n values to be calculated into your formula yo
would use a syntax like:
Code
-------------------
"=Average(Cells(" & n & ", 1), Cells(" & n & ", 2))
-------------------
which would result in a string that changes with the n value.
But... that does not solve your problem, because the above string doe
not result in a valid formula
I would recommend using the following syntax, which is not dependent o
the row number:
Code
-------------------
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-3]:RC[-2])
-------------------
This formula calculates the average of the values in two cells
relative to the currently selected cell.
The first cell is 3 columns to the left "RC[-3]" of the curren
position, the second is 2 columns to the left "RC[-2]".
If you would want to calculate the average of two values in columns
and B and put the average in column D, until there are no more value
in column A, you could use the following code:
Code
-------------------
Sub Macro3()
Dim Row As Integer
Range("D1").Select
Row = 1
Do
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-3]:RC[-2])"
ActiveCell.Offset(1, 0).Select
Row = Row + 1
Loop Until IsEmpty(Cells(Row, 1))
End Sub
-------------------
Good luck
--
Message posted from
http://www.ExcelForum.com