LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default macro to calculate average on varying sized rows with missing valu


Hi,

I'm using excel 2003. I'd like to calculate the average associated with a
large number of rows across five columns. Note that in some cells there are
missing values or even #VALUE! errors (ie., because the averages are based on
values derived from other calculations). For a single row, the following
formula works very well:

=IF(COUNT(DM2,DN2,DO2,DP2,DQ2)=5, (DM2+DN2+DO2+DP2+DR2)/5,"")

Now, I would like to incorporate this formula into a macro which could be
applied to different data sets, which will have different numbers of
cases/rows. My current macro looks like this, but it doesn't work. I get an
error on the 'Cells(role_average, 162) = ...' line.

Any suggestions would be much appreciated.

Dim role_average As Integer
Dim q1_dif_data As Integer
Dim q2_dif_data As Integer
Dim q3_dif_data As Integer
Dim q4_dif_data As Integer
Dim q5_dif_data As Integer

With Sheets("Data")
q1_dif_data = .Cells(65536, 117).End(xlUp).Row
q2_dif_data = .Cells(65536, 118).End(xlUp).Row
q3_dif_data = .Cells(65536, 119).End(xlUp).Row
q4_dif_data = .Cells(65536, 120).End(xlUp).Row
q5_dif_data = .Cells(65536, 121).End(xlUp).Row

Cells(role_average, 162) =
"=IF(COUNT(q1_dif_data,q2_dif_data,q3_dif_data,q4_ dif_data,q5_dif_data)=5,
(q1_dif_data+q2_dif_data+q3_dif_data+q4_dif_data+q 5_dif_data)/5,"")"

End With
Range("Data!FF1") = "Role -- Average"
End Sub
 
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
Calculate AVERAGe with #MISSING! Arne Hegefors Excel Worksheet Functions 2 February 3rd 09 03:58 AM
Calculate average with missing values Arne Hegefors Excel Worksheet Functions 2 January 14th 09 10:02 AM
How to calculate an average from various rows??? paulk2002 Excel Worksheet Functions 3 July 7th 08 10:00 AM
Selectdown Macro w/ varying rows Ron de Bruin Excel Programming 1 December 7th 06 10:22 PM
Variable sized average macro/function danwtf2004 Excel Programming 2 January 29th 04 10:11 PM


All times are GMT +1. The time now is 08:39 AM.

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

About Us

"It's about Microsoft Excel"