Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Get Average on results of Autofilter

I have an excel spreadsheet has the auto filter turned on. After I
filter the data for a specific user, I would like to get an average of
a column of just those filter results. Is there an easy way to do this
in my VBA code? I am using the average in my code for further
calculations so I dont want to use the =SUBTOTAL function to display it
on the worksheet.

Any ideas?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Get Average on results of Autofilter

One way

Sub test()
Dim nm As Name
Dim x As Double

On Error Resume Next

Set nm = ActiveSheet.Names("_FilterDatabase")

If Not nm Is Nothing Then
'avg of 2nd col of the filter range
x = Application.Subtotal(1, Range(nm).Columns(2))
End If

End Sub

Regards,
Peter T

wrote in message
oups.com...
I have an excel spreadsheet has the auto filter turned on. After I
filter the data for a specific user, I would like to get an average of
a column of just those filter results. Is there an easy way to do this
in my VBA code? I am using the average in my code for further
calculations so I dont want to use the =SUBTOTAL function to display it
on the worksheet.

Any ideas?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Get Average on results of Autofilter

Just to clarify is "_FilterDatabase" the already filtered result set?
or would that be the entire worksheet?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Get Average on results of Autofilter

"_FilterDatabase" is a hidden Worksheet name applied by Excel that defines
the current filter range, or the last one if filter has been removed (the
name persists after removing the filter). If not removed by other means the
formula will still work. That may or may not be useful for you.

Plenty of other ways, probably you already know the filter range and if a
filter is applied, so use that in a similar formula.

If ActiveSheet.AutoFilterMode Then
Set r = ActiveSheet.AutoFilter.Range
MsgBox r.Address
End If

Or loop through non hidden rows.

Regards,
Peter T


wrote in message
oups.com...
Just to clarify is "_FilterDatabase" the already filtered result set?
or would that be the entire worksheet?



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
emailing autofilter results Dianeg Excel Worksheet Functions 3 January 19th 10 10:02 AM
Average over autofilter results QB Excel Worksheet Functions 4 September 30th 09 04:17 PM
Autofilter results Ben Wunderin Excel Discussion (Misc queries) 3 December 2nd 08 12:31 AM
Strange Results with Autofilter Joyce Excel Discussion (Misc queries) 1 January 17th 05 02:42 AM
Count of results in AutoFilter andrew Excel Programming 3 October 2nd 04 12:45 AM


All times are GMT +1. The time now is 07:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"