View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
SmartbizAustralia SmartbizAustralia is offline
external usenet poster
 
Posts: 6
Default UDF in Excel 2007 for Filter or Query

you can do most of that with formulae.

That being said a simple vba loop can add up all the numbers whilst
doing a count and get an average by dividing these.

ALso getting a max or min based on some filter critieria is just a
loop.

Dim ws as worksheet
Dim dblTotal as double
Dim lngCount as long
Dim dblAverage as double
Dim dblMin as double
Dim dblMax as double

set ws = thisowkrbook.worksheets("my data")
dblTotal = 0
lngCount = 0
For lngRow = 1 to LastRowInSheet
if ws.cells(lngrow,1) = SomeCriteria then
dblTotal = dblTotal + ws.cells(lngrow,2)
lngCount = lngCount + 1
if dblMin ws.cells(lngrow,2) then dblMin = ws.cells(lngrow,2)
if dblMax < ws.cells(lngrow,2) then dblMin = ws.cells(lngrow,2)
end if

next lngRow
dblAverage = dblTotal/lngCount

Regards,
Tom Bizannes
Excel Development
Sydney, Australia
Industrial Strength Excel Development
http://www.macroview.com.au