Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default how do you skip empty cells or zeros when calculating the average

In my calculation where I find the last row and calculate the average of the
last 30 sets of data, I come across zeros. How do I ignore zeros in VB
macros.

Ex.
0 (or empty set in some cases)
3
6
9
12
average = 6 in Macro
The average should be 7.5 because first value was zero (or nearly zero)
which means I'm going to have to do some kind of test that says if the zero
value is less than .01, ignore it when calculating the average.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 527
Default how do you skip empty cells or zeros when calculating the average

Something like this should do it

Function myAvg(ByVal data) As Double
Dim count As Integer, mySum As Double
For Each c In data
If IsNumeric(c) And c = 1 Then
mySum = mySum + c
count = count + 1
End If
Next
myAvg = mySum / count
End Function

Peter

"soccerdav2003" wrote:

In my calculation where I find the last row and calculate the average of the
last 30 sets of data, I come across zeros. How do I ignore zeros in VB
macros.

Ex.
0 (or empty set in some cases)
3
6
9
12
average = 6 in Macro
The average should be 7.5 because first value was zero (or nearly zero)
which means I'm going to have to do some kind of test that says if the zero
value is less than .01, ignore it when calculating the average.

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
skip cells with zero values in chart (cells not empty) jhall@ifox Charts and Charting in Excel 3 June 2nd 09 02:11 PM
I want the autofill/drag function to skip empty cells tcmcgee Excel Discussion (Misc queries) 1 October 28th 08 04:27 PM
How do I get an average for 5 when I need to skip cells? Troy H Excel Discussion (Misc queries) 7 February 5th 06 02:21 PM
How to skip empty cells while running a macro? saziz[_2_] Excel Programming 5 June 10th 04 11:16 PM
Skip empty and text cells Jason Morin[_3_] Excel Programming 3 April 2nd 04 10:22 PM


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