multiple filter selection using VBA macro

mobeenraheem

New Member
Joined
Oct 24, 2014
Messages
4
Hi

I am trying to achieve multiple filter selection using VBA macro but its not working as it should.

Below macro is working fine when there is two values.its not working more then two values.
Can please someone tell me what i am missing.

Code:
Sub Macro1()
'
' Macro1 Macro
'


'
    Columns("A:A").Select
    Selection.AutoFilter
    Range("A1").Select
    ActiveSheet.Range("$A$1:$A$11076").AutoFilter Field:=1, Criteria1:=Array( _
        "=*value1)*", "=*value2*", "=*value3*", "=*value4*"), Operator:=xlFilterValues
End Sub
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
suppose data is like this

hdng1hdng2
aa1
as2
dd3
fg4
gh5
as6
sd7
df8
fg9
gh0
a9
hg8
gf7
fg6
jg5

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>




somehow more tha two criteria does not work even using array function. experts may give better explanation. I subvert this by this macro. try that and use it by modifying.see variable x(1),x(2) and x(3)
the result of macro is in sheet2

Code:
Sub test()
Dim x(1 To 3), j As Integer
Dim r As Range
x(1) = "a*"
x(2) = "s*"
x(3) = "d*"
Worksheets("sheet2").Cells.Clear
Worksheets("sheet1").Activate
Set r = Range("A1").CurrentRegion


r.AutoFilter field:=1, Criteria1:=Array(x(1), x(2)), Operator:=xlFilterValues
r.Offset(1, 0).Resize(r.Rows.Count - 1).Copy Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    
     ActiveSheet.AutoFilterMode = False
     r.AutoFilter field:=1, Criteria1:=x(3)
    r.Offset(1, 0).Resize(r.Rows.Count - 1).Copy Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
     ActiveSheet.AutoFilterMode = False
MsgBox "macro done see sheete2"
End Sub
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
42,244
Office Version
365
Platform
Windows
Below macro is working fine when there is two values.its not working more then two values.
Can please someone tell me what i am missing.
Using AutoFilter with Text Filters as you are trying to do here only allows two values - It is just an Excel limit.
If you manually try AutoFilter in the sheet and choose 'Text Filters' from the drop-down, you only get the choice of two, whether it be "Equals", "Begins with", "Contains" etc.
 

Forum statistics

Threads
1,082,040
Messages
5,362,804
Members
400,693
Latest member
jenlj

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top