LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Sorting a Filtered List

Frank,
Worked like a charm! Thanks for your help. (I had
attempted this before but did not succeed).

Alex J
-----Original Message-----
Hi
one way in VBA: First storing the autofilter settings in

your current
worksheet, applying the sort, restoring the filter

settings.
Note: in the following example i have just inserted a

quite simple,
recorded sort statement - adapt this to your needs
Try (Saving and Restoring the filter - copied from the

Excel help)

Sub Sort_with_filters()
Dim w As Worksheet
Dim filterArray()
Dim currentFiltRange As String
Dim f As Integer
Dim col As Integer
Set w = ActiveSheet

'Save current Autofilter settings
With w.AutoFilter
currentFiltRange = .Range.Address
With .Filters
ReDim filterArray(1 To .Count, 1 To 3)
For f = 1 To .Count
With .Item(f)
If .On Then
filterArray(f, 1) = .Criteria1
If .Operator Then
filterArray(f, 2) = .Operator
filterArray(f, 3) = .Criteria2
End If
End If
End With
Next
End With
End With
w.AutoFilterMode = False

'do the sorting just an example - change this to your

needs
Range("A1:C4").Sort Key1:=Range("C1"),

Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal


'Restore the filter
For col = 1 To UBound(filterArray(), 1)
If Not IsEmpty(filterArray(col, 1)) Then
If filterArray(col, 2) Then
w.Range(currentFiltRange).AutoFilter

field:=col, _
Criteria1:=filterArray(col, 1), _
Operator:=filterArray(col, 2), _
Criteria2:=filterArray(col, 3)
Else
w.Range(currentFiltRange).AutoFilter

field:=col, _
Criteria1:=filterArray(col, 1)
End If
End If
Next
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

Alex J wrote:
All,
I have found that applying a Sort command to a Filtered

list anly
seems to sort the visible (non filtered) rows.
Is there a way (in VBA) to apply the sort to all of the

rows in the
field, including the hidden ones, without removing and

then
re-applying the filter?

Alex J


.

 
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
Sorting and subtotal in a filtered list Ken W Excel Discussion (Misc queries) 1 December 1st 09 08:02 PM
Hold conditional formatting when sorting filtered data Pyitty Excel Discussion (Misc queries) 1 July 6th 09 09:09 AM
A list of what is being filtered on? Mel Excel Discussion (Misc queries) 5 August 27th 08 05:08 PM
Summing a filtered list Neil Excel Discussion (Misc queries) 4 September 21st 07 07:40 PM
Filtered Sorting - Please Help! SmokingMirror Excel Discussion (Misc queries) 2 July 26th 06 03:20 PM


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