Thread: averages
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Donald Lloyd Donald Lloyd is offline
external usenet poster
 
Posts: 30
Default averages

David,

Try this, changing the fixed rows and column to suit.
I trust the variable names used are reasonably self-explanatory.

Sub RowAverage()
Dim HdrRow, DataRow1, DataRowLast, FirstDataCol
Dim EndCol, TotRows, Fma, FmaRow

'Change these to suit
HdrRow = 1: FirstDataCol = 3' (C)
DataRow1 = 2: DataRowLast = 10

EndCol = Cells(HdrRow, FirstDataCol).End(xlToRight).Column
TotRows = DataRowLast - DataRow1 + 1
Fma = "=Average(r[-" & TotRows & "]C:R[-1]C)"
FmaRow = DataRowLast + 1
Range(Cells(FmaRow, FirstDataCol), Cells(FmaRow, EndCol)) = Fma
End Sub

regards,
Don Lloyd

--

"david" wrote in message
...
I am trying to find the averages of a certain range. I
have a spreadsheet that takes information from other
sheets and copy and pastes a column to my summary page. I
need to find the averages of the information on the
summary page. The only problem is that the range of
information changes. It always has the same number of
rows, but the number of columns change. Each column is for
a different company, and there are not always the same
number of companies. So, how do I write a macro that will
find out how many columns it needs to find the average for.

Thanks,
David