Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Formula req for macro

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)"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Formula req for macro

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.


"Gautam" wrote:

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)"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Formula req for macro

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


--
Don Guillett
SalesAid Software

"Gautam" wrote in message
ups.com...
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)"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula in macro Lori Excel Worksheet Functions 6 May 11th 07 02:33 PM
Formula in macro causes macro to fail KCK Excel Programming 2 February 8th 07 08:47 PM
Formula in a Macro Trevor Shuttleworth Excel Programming 0 January 9th 07 06:48 PM
Formula expected end of statement error, typing formula into cell as part of VBA macro [email protected] Excel Programming 1 July 20th 06 07:58 PM
Help With Formula and Macro Please Chris E.[_2_] Excel Programming 0 January 31st 06 07:25 PM


All times are GMT +1. The time now is 06:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"