Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA AVERAGE formula, ignoring zeros

I have the following code:


'Average applicable cells ignoring zeros
Worksheets("Summary").Range("H5").Formula = "=Average('" &
startsheet & ":" & endsheet & "'!H5)"


The problem is that the formula as written includes zeros in the
average. I need to ignore zeros.

Some background:

This is only a portion of a subroutine

The routine then goes on to copy the newly writtem formula (note the
relative fererence) to other selected cells on the sheet "Summary"

The "startsheet" and "endsheet" strings used in the formula can change
depending on which sheets are specified by the user so I need to keep
this logic

Can anyone help we with a formula to average the range specified,
ignoring zeros?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default VBA AVERAGE formula, ignoring zeros

Guy

It will take an array formula to get the average, and this
3-d-kind of an array formula is not possible in Excel (I believe).

Maybe you can use part of the below code

Sub TestAverage()
'Leo Heuser, 10 Jan. 2004
Dim Ave As Double
Dim Counter As Long
Dim EndSheet As String
Dim Index1 As Long
Dim Index2 As Long
Dim Sh As Worksheet
Dim SheetArray As Variant
Dim StartSheet As String
Dim Total As Double

StartSheet = "Sheet4"
EndSheet = "Sheet12"


Index1 = Sheets(StartSheet).Index
Index2 = Sheets(EndSheet).Index

SheetArray = _
Application.WorksheetFunction. _
Transpose(Evaluate("Row(" & Index1 & ":" & Index2 & ")"))

For Each Sh In Sheets(SheetArray)
With Sh.Range("H4")
If .Value < 0 And .Value < "" Then
Counter = Counter + 1
Total = Total + .Value
End If
End With
Next Sh

Ave = Total / Counter

MsgBox Ave
End Sub



--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Guy Hoffman " skrev i en
meddelelse ...
I have the following code:


'Average applicable cells ignoring zeros
Worksheets("Summary").Range("H5").Formula = "=Average('" &
startsheet & ":" & endsheet & "'!H5)"


The problem is that the formula as written includes zeros in the
average. I need to ignore zeros.

Some background:

This is only a portion of a subroutine

The routine then goes on to copy the newly writtem formula (note the
relative fererence) to other selected cells on the sheet "Summary"

The "startsheet" and "endsheet" strings used in the formula can change
depending on which sheets are specified by the user so I need to keep
this logic

Can anyone help we with a formula to average the range specified,
ignoring zeros?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA AVERAGE formula, ignoring zeros

Hard to believe the countif function is so limited (i.e., cannot use o
3D ref). Thanks for the code. I'll give it a try.

G

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default VBA AVERAGE formula, ignoring zeros

You're welcome.

LeoH

"Guy Hoffman " skrev i en
meddelelse ...
Hard to believe the countif function is so limited (i.e., cannot use on
3D ref). Thanks for the code. I'll give it a try.

GH



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA AVERAGE formula, ignoring zeros

You could use the database worksheet function DAVERAGE

"Guy Hoffman " wrote in message
...
The problem is that the formula as written includes zeros in the
average. I need to ignore zeros.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA AVERAGE formula, ignoring zeros

I couldn't get the DAverage function to work if the database was a 3D
reference


---
Message posted from http://www.ExcelForum.com/

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
Average formula where blank cells are counted as zeros krwelling Excel Worksheet Functions 5 May 20th 23 11:43 AM
Average from three different coworkers excluding zeros formula? Rhett C[_2_] Excel Discussion (Misc queries) 3 November 1st 08 09:58 PM
Average ignoring Zeros Gary Excel Worksheet Functions 3 February 21st 07 02:20 AM
Averaging, ignoring zeros Mark Excel Worksheet Functions 5 February 28th 05 10:25 PM
Formula to average ignoring negatives? Steve Excel Discussion (Misc queries) 16 January 1st 05 12:57 PM


All times are GMT +1. The time now is 11:33 AM.

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"