Autofilter in conjunction with Advanced Filter

Emmily

Well-known Member
Joined
Oct 5, 2008
Messages
676
Hi, is there a way to have autofilter turned on when the data is filtered via advanced filter, I have a VBA code which has advanced filter code but i would like to have the autofilter turned on, so the user can use the filter, as soon as i manually apply the filter the data reverts to all data


With Sheets("SecuritiesReport").Range("A5").CurrentRegion
.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("rngTeam")
End With
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
These are the criterias


<TABLE style="WIDTH: 48pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=64 border=0 x:str><COLGROUP><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD class=xl22 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 48pt; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=64 height=17>BANK</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl23 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>CITI</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl23 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>JPM</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl23 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>RBS</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD class=xl23 style="BORDER-RIGHT: windowtext 0.5pt solid; BORDER-TOP: windowtext; BORDER-LEFT: windowtext 0.5pt solid; BORDER-BOTTOM: windowtext 0.5pt solid; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>BONY</TD></TR></TBODY></TABLE>
 
Upvote 0
Hi, is there a way to have autofilter turned on when the data is filtered via advanced filter, I have a VBA code which has advanced filter code but i would like to have the autofilter turned on, so the user can use the filter, as soon as i manually apply the filter the data reverts to all data


With Sheets("SecuritiesReport").Range("A5").CurrentRegion
.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("rngTeam")
End With

Try this:

<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL><COL><COL><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>A</TH><TH>B</TH><TH>C</TH><TH>D</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">1</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">2</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">3</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">4</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">5</TD><TD style="TEXT-ALIGN: center">Cod</TD><TD style="TEXT-ALIGN: center">Company</TD><TD style="TEXT-ALIGN: center">Contact</TD><TD style="TEXT-ALIGN: center">Bank</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">6</TD><TD style="TEXT-ALIGN: center">3051</TD><TD style="TEXT-ALIGN: center">Company01</TD><TD style="TEXT-ALIGN: center">Name01</TD><TD>CITI </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">8</TD><TD style="TEXT-ALIGN: center">6527</TD><TD style="TEXT-ALIGN: center">Company03</TD><TD style="TEXT-ALIGN: center">Name03</TD><TD>RBS </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">10</TD><TD style="TEXT-ALIGN: center">7580</TD><TD style="TEXT-ALIGN: center">Company05</TD><TD style="TEXT-ALIGN: center">Name05</TD><TD>CITI </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">12</TD><TD style="TEXT-ALIGN: center">4713</TD><TD style="TEXT-ALIGN: center">Company07</TD><TD style="TEXT-ALIGN: center">Name07</TD><TD>RBS </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">13</TD><TD style="TEXT-ALIGN: center">1243</TD><TD style="TEXT-ALIGN: center">Company08</TD><TD style="TEXT-ALIGN: center">Name08</TD><TD>BONY </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">14</TD><TD style="TEXT-ALIGN: center">2461</TD><TD style="TEXT-ALIGN: center">Company09</TD><TD style="TEXT-ALIGN: center">Name09</TD><TD>CITI </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">15</TD><TD style="TEXT-ALIGN: center">7546</TD><TD style="TEXT-ALIGN: center">Company10</TD><TD style="TEXT-ALIGN: center">Name10</TD><TD>JPM </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">17</TD><TD style="TEXT-ALIGN: center">7649</TD><TD style="TEXT-ALIGN: center">Company12</TD><TD style="TEXT-ALIGN: center">Name12</TD><TD>BONY </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">18</TD><TD style="TEXT-ALIGN: center">6197</TD><TD style="TEXT-ALIGN: center">Company13</TD><TD style="TEXT-ALIGN: center">Name13</TD><TD>CITI </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">20</TD><TD style="TEXT-ALIGN: center">6860</TD><TD style="TEXT-ALIGN: center">Company15</TD><TD style="TEXT-ALIGN: center">Name15</TD><TD>RBS </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">21</TD><TD style="TEXT-ALIGN: center">8123</TD><TD style="TEXT-ALIGN: center">Company16</TD><TD style="TEXT-ALIGN: center">Name16</TD><TD>BONY </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">23</TD><TD style="TEXT-ALIGN: center">8190</TD><TD style="TEXT-ALIGN: center">Company18</TD><TD style="TEXT-ALIGN: center">Name18</TD><TD>JPM </TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">25</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">26</TD><TD>************</TD><TD>************</TD><TD>************</TD><TD>************</TD></TR></TBODY></TABLE>


Code:
Sub AutoFilterCustom()
'
'Prg    : AutoFilterCustom
'Author : Markmzz
'Date   : 06/07/2011
'Version: 01
 
    'Configures the Autofilter only for
    'columns Cod, Company and Contact
    '(columns 1, 2 and 3) and filter the data
    'by field Bank by criteria: CITI, JPM, RBS and BONY
 
    'Define the macro variables
    Dim FinalRow, FinalCol, myrngTeam, i As Long
    Dim myRange As Range
    Dim myArray() As Variant
 
    'Activates the sheet [FONT=Arial]SecuritiesReport[/FONT]
    Sheets("[FONT=Arial]SecuritiesReport[/FONT]").Activate
 
    'Determine the number of criterias
    myrngTeam = WorksheetFunction.Max( _
        Range("rngTeam").Rows.Count, Range("rngTeam").Columns.Count)
 
    ReDim myArray(1 To myrngTeam)
 
    'Determines the last row and column
    'of your input range (database)
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    FinalCol = Cells(5, Columns.Count).End(xlToLeft).Column
 
    'References the list range
    Set myRange = Range(Cells(5, 1), Cells(FinalRow, FinalCol))
 
    'Disables and enables the Autofilter,
    'for remove any previous customization,
    'and enable the AutoFilter
 
    'Enables/disables the Autofilter
    myRange.AutoFilter
 
    'Checks whether the database is not
    'Active Filtered
    If Not ActiveSheet.AutoFilterMode Then
        'Enables the AutoFiltro
        myRange.AutoFilter
    End If
 
    'Create the array CITI, JPM, RBS and BONY
    i = 1
    For Each myCell In Range("rngTeam")
        myArray(i) = myCell.Value
        i = i + 1
    Next myCell
 
    'AutoFilter the data by field Bank
    'by criterion: CITI, JPM, RBS and BONY
    'and disables the icon DropDown of the
    'respective field
    myRange.AutoFilter _
        Field:=4, _
        Criteria1:=myArray, _
        Operator:=xlFilterValues, _
        VisibleDropDown:=False
 
    'Frees the memory used
    'by object variable
    Set myRange = Nothing
End Sub

Markmzz
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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