PC Review


Reply
Thread Tools Rate Thread

how do you skip empty cells or zeros when calculating the average

 
 
soccerdav2003
Guest
Posts: n/a
 
      11th Jun 2008
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 With Quote
 
 
 
 
Billy Liddel
Guest
Posts: n/a
 
      12th Jun 2008
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
skip cells with zero values in chart (cells not empty) =?Utf-8?B?amhhbGxAaWZveA==?= Microsoft Excel Charting 3 2nd Jun 2009 02:11 PM
How to skip the blank cells for calculating StdDev? =?Utf-8?B?RXJpYw==?= Microsoft Excel Worksheet Functions 3 7th Nov 2006 12:00 AM
How to skip the blank cells for calculating StdDev? =?Utf-8?B?RXJpYw==?= Microsoft Excel Misc 1 6th Nov 2006 08:27 AM
How to skip the blank cells for calculating StdDev? =?Utf-8?B?RXJpYw==?= Microsoft Excel Worksheet Functions 3 6th Nov 2006 07:38 AM
How do I get an average for 5 when I need to skip cells? =?Utf-8?B?VHJveSBI?= Microsoft Excel Misc 7 5th Feb 2006 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.