Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default average of values 0


Is there a way to make the average funtion work in vba so that it
selects only values 0 in a given range?
Something like
avv = Application.WorksheetFunction.Average(if(Range("'d ata'!" & srt) 0))

=average(if(b2.b5000))

works in excel and I'd like the equivqlent in vba if possible
Thanks
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default average of values 0

Hi Chris,

you can use this:
=worksheetfunction.SumIf(selection,"0",selection)/worksheetfunction.CountIf(selection,"0")

replace selection with range you wish

regards,
Ivan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default average of values 0

how about something like this?

Range("a1").Value = WorksheetFunction.Sum(Range("b2:b500")) / _
WorksheetFunction.CountIf(Range("b2:b500"), "0")

--


Gary


"inquirer" wrote in message
...

Is there a way to make the average funtion work in vba so that it selects only
values 0 in a given range?
Something like
avv = Application.WorksheetFunction.Average(if(Range("'d ata'!" & srt) 0))

=average(if(b2.b5000))

works in excel and I'd like the equivqlent in vba if possible
Thanks
Chris



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default average of values 0

or this
Range("a1").FormulaArray = "=average(if(b2:b5000,b2:b500))"

--


Gary


"inquirer" wrote in message
...

Is there a way to make the average funtion work in vba so that it selects only
values 0 in a given range?
Something like
avv = Application.WorksheetFunction.Average(if(Range("'d ata'!" & srt) 0))

=average(if(b2.b5000))

works in excel and I'd like the equivqlent in vba if possible
Thanks
Chris



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default average of values 0

or even

Range("a1").Value = Evaluate("=average(if(b2:b5000,b2:b500))")

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
or this
Range("a1").FormulaArray = "=average(if(b2:b5000,b2:b500))"

--


Gary


"inquirer" wrote in message
...

Is there a way to make the average funtion work in vba so that it

selects only
values 0 in a given range?
Something like
avv = Application.WorksheetFunction.Average(if(Range("'d ata'!" & srt)

0))

=average(if(b2.b5000))

works in excel and I'd like the equivqlent in vba if possible
Thanks
Chris







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default average of values 0

inquirer wrote:

Is there a way to make the average funtion work in vba so that it
selects only values 0 in a given range?
Something like
avv = Application.WorksheetFunction.Average(if(Range("'d ata'!" & srt) 0))

=average(if(b2.b5000))

works in excel and I'd like the equivqlent in vba if possible
Thanks
Chris

I guess I didn't make myself clear... what I was looking for two things:
how to put a named range into the worksheet function (the way I was
doing it doesn't seem to work), and
how to use a conditional statement in the function.

Ivan's solution is fine for getting averages but what about other
functions like stdev and var?

Thanks
Chris
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
A formula to AVERAGE IF but only average a set number of values [email protected] Excel Worksheet Functions 2 January 31st 08 08:28 PM
average values in non-contiguous cells, ignoring 0 values RWormdahl Excel Worksheet Functions 3 October 30th 06 01:06 AM
Average non zero values PA Excel Worksheet Functions 8 June 10th 06 02:15 AM
Average AM or PM values David Excel Discussion (Misc queries) 9 May 6th 06 02:31 PM
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Excel Worksheet Functions 13 July 31st 05 03:59 PM


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