Multilevel Autofilter

G2K

Active Member
Joined
May 29, 2009
Messages
355
Hi,

can anybody help me to apply multilevel filter in vba i am trying to apply 2 levels if autofilter in VBA, but it removes filter apply filter again on selected region

below is the code

Private Sub test()
Dim Sh As Worksheet
Dim Rng As Range
Dim Rnge As Range
Dim ws As Worksheet
Dim Cell As Range
Dim TheList As New Collection
Dim Slist As New Collection
Dim i As Integer
Dim Rcount As Long
Dim eSum As Long
Dim ShTarget As Worksheet
Set Sh = Worksheets("Data")
With Sh
Set Rng = .Range("G2:G" & .Range("G" & .Rows.Count).End(xlUp).Row)
End With

On Error Resume Next
For Each Cell In Rng
TheList.Add Cell.Value, CStr(Cell.Value)
Next Cell

With Sh
Set Rnge = .Range("H2:H" & .Range("H" & .Rows.Count).End(xlUp).Row)
End With

On Error Resume Next
For Each Cell In Rnge
Slist.Add Cell.Value, CStr(Cell.Value)
Next Cell

MsgBox Slist.Count
On Error GoTo 0
Set Rng = Sh.Range("A1").CurrentRegion
Set Rnge = Sh.Range("A1").CurrentRegion
For l = 1 To Slist.Count
For i = 1 To TheList.Count
Rnge.AutoFilter
Rnge.AutoFilter field:=8, Criteria1:=Slist(l)
MsgBox Slist(l)
Rng.AutoFilter
Rng.AutoFilter field:=7, Criteria1:=TheList(i)
Rcount = Rng.SpecialCells(xlCellTypeVisible).Count

Set ShTarget = Works


MsgBox TheList(i) & "-" & Rcount

'Rng.SpecialCells(xlCellTypeVisible).Copy ShTarget.Range("A1")
Next i
Next l
With Sh
.AutoFilterMode = False
.Select
End With
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Thanks Andrew,

got the point just after posting the thread, would appriciate if you help me to get the sum of the data in next column on the same cretaria

lets Column c is filtered on certain criteria and i want to add visible rows in column D.


Thanks
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top