Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default formula help needed for averages

Or, if you prefer an "unsimple" approach, here's some code that'll do
the same thing (just pass a reference to your range into it):

Public Function AverageTheCells(objRange As Range)

Dim nCell As Integer
Dim lTotal As Long
Dim nDenominator As Integer
Dim lAverage As Long

For nCell = 1 To objRange.Cells.Count
If objRange.Cells(nCell, 1).Value 0 Then
nDenominator = nDenominator + 1
lTotal = lTotal + objRange.Cells(nCell, 1).Value
End If
Next nCell

If nDenominator 0 Then AverageTheCells = lTotal / nDenominator

End Function


Alok wrote:
Use countif

=COUNTIF(A1:A5,"0")

"phil-rge-ee" wrote:

I have a cells C21 thru C45 that have numbers in them. I need to add them all
together and then divide by the number of cells that have a number greater
than 0 in them. This would be used to get an average number. If the cell is 0
then I don't want to include it in the dividing process. Example:
C21 is 5
C22 is 3
C23 is 0
C24 is 7
C25 is 0

I would need the formula or VB script to add the numbers then divide by 3
(not divide by 5 - eliminating the cells with 0 in them) So the answer in the
example here would be 5, not 3. (15 divided by 3).
Thanks for any help.

Phil


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 for averages JNSteiner Excel Discussion (Misc queries) 1 June 1st 10 11:32 PM
help with averages formula Jesse Blanchard[_2_] Excel Discussion (Misc queries) 2 February 4th 09 10:30 PM
help with averages formula Luke M Excel Discussion (Misc queries) 0 February 4th 09 09:06 PM
formula help needed for averages Brad Excel Programming 0 January 10th 07 06:41 PM
averages formula Gerald Excel Worksheet Functions 1 July 4th 05 04:50 PM


All times are GMT +1. The time now is 08:44 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"