Formula req for macro

  • Thread starter Thread starter Gautam
  • Start date Start date
G

Gautam

I need a macro which calculates the average for each column, tried the
following code, but didn't work out
activesheet.cells(1,1).formulaR1C1="=Average(R[maxrow]C:R[-2]C)"
 
I presume you calculate maxrow somewhere else.


Try this:

activesheet.cells(1,1).formulaR1C1="=Average(R[" & maxrow & "]C:R[-2]C)"

You will run into a problem with this because your formula is trying to go
up 2 rows from activesheet.cells(1,1) and it can't do that.
 
Assuming your data for each column starts in row 2 and you want the answer
in row 1.
Sub averagecolumns()
For i = 1 To 8 'num columns
Cells(1, i) = Application.Average(Columns(i))
Next i
End Sub
 
Back
Top