Smart Auto filter VBA

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Hello,

Example sheet1 contain data I need Smart Auto filter VBA which select “Field and Criteria” from sheet2 and apply filter to sheet1


Book1
ABCDEFGHIJKLMNO
1DateP1P2P3P4P5P6P7P8P9P10P11P12P13P14
2DateP1P2P3P4P5P6P7P8P9P10P11P12P13P14
301/12/20132X2111X1112X11
402/12/201322X121XX21212X
503/12/201311111X1X11XX12
604/12/201311121112X111X1
705/12/20131X11X12X11111X
806/12/201311122X111X111X
907/12/201311X111121X11X1
1008/12/2013121111211X1112
1109/12/201322X2112X211X12
1210/12/2013X1111221121X11
1311/12/20131211X1111XX1XX
1412/12/2013112X2212X11X21
1513/12/20131X1X1221111222
1614/12/2013XX11211222X111
1715/12/201322222X1112X2X1
1816/12/2013X111XXX111X122
1917/12/201322X1212121X11X
2018/12/2013X1121121X2X221
2119/12/2013111212X22X1211
2220/12/20132111X211X1X122
Sheet1


Sheet2 data looks as shown below
Example1
Smart VBA…. can give these following options to filter data
1st Select Field from column ‘A’ header for example A1= P2|P5|P7 So Field:=2, Field:=5, Field:=7
2nd VBA gives input option to select any cell in column A2 To down for Criteria selection for example if we select A5 = X|X|2 So Criteria1:=X, Criteria1:=X, Criteria1:=1
Filter selection would be as shown below
AutoFilter Field:=2, Criteria1:=X
AutoFilter Field:=5, Criteria1:=X
AutoFilter Field:=7, Criteria1:=1


Book1
A
1P2|P5|P7
2X|1|X
32|2|X
41|1|1
5X|X|2
61|2|1
72|1|2
81|1|2
92|X|1
10X|1|2
11X|2|1
122|2|1
131|X|X
142|2|2
151|1|X
161|X|1
Sheet2


Sheet2 data looks as shown below
Example2
Smart VBA…. can give these following options to filter data
1st Select Field from column ‘A’ header for example A1= P3|P7|P10 So Field:=3, Field:=7, Field:=10
2nd VBA gives input option to select any cell in column A2 To down for Criteria selection for example if we select A2 = 2|X|1 So Criteria1:=2, Criteria1:=X, Criteria1:=1
Filter selection would be as shown below
AutoFilter Field:=3, Criteria1:=2
AutoFilter Field:=7, Criteria1:=X
AutoFilter Field:=10, Criteria1:=1


Book1
A
1P3|P7|P10
22|X|1
3X|X|1
41|1|1
51|2|1
61|1|X
7X|1|X
81|2|X
9X|2|1
101|2|2
112|1|1
121|1|2
132|1|2
141|X|1
151|X|X
Sheet2


Sheet2 data looks as shown below
Example3
Smart VBA…. can give these following options to filter data
1st Select Field from column ‘A’ header for example A1= P1|P7|P12|P14So Field:=1, Field:=7, Field:=12 , Field:=14
2nd VBA gives input option to select any cell in column A2 To down for Criteria selection for example if we select A3 = 2|X|1|X So Criteria1:=2, Criteria1:=X, Criteria1:=1, Criteria1:=X
Filter selection would be as shown below
AutoFilter Field:=1, Criteria1:=2
AutoFilter Field:=7, Criteria1:=X
AutoFilter Field:=12, Criteria1:=1
AutoFilter Field:=14, Criteria1:=X


Book1
A
1P1|P7|P12|P14
22|X|X|1
32|X|1|X
41|1|X|2
51|1|1|1
61|2|1|X
71|1|1|X
81|2|1|2
92|2|X|2
10X|2|X|1
111|1|X|1
121|2|2|2
13X|1|1|1
142|1|2|1
15X|X|1|2
162|2|1|X
17X|2|2|1
181|X|2|1
192|1|1|2
Sheet2


Does it is feasible

Using Excel Version 2000

Thank You

Regards,
Kishan
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Example1
Smart VBA…. can give these following options to filter data
1st Select Field from column ‘A’ header for example A1= P2|P5|P7 So Field:=2, Field:=5, Field:=7
2nd VBA gives input option to select any cell in column A2 To down for Criteria selection for example if we select A5 = X|X|2 So Criteria1:=X, Criteria1:=X, Criteria1:=1
Filter selection would be as shown below
AutoFilter Field:=2, Criteria1:=X
AutoFilter Field:=5, Criteria1:=X
AutoFilter Field:=7, Criteria1:=1

A
1P2|P5|P7
2X|1|X
32|2|X
41|1|1
5X|X|2
61|2|1
72|1|2
81|1|2
92|X|1
10X|1|2
11X|2|1
122|2|1
131|X|X
142|2|2
151|1|X
161|X|1

<tbody>
</tbody>
Sheet2

Hi,

Re reading my query I found in given example1 “Criteria” is not define correctly
Example1
Smart VBA…. can give these following options to filter data
1st Select Field from column ‘A’ header for example A1= P2|P5|P7 So Field:=2, Field:=5, Field:=7
2nd VBA gives input option to select any cell in column A2 To down for Criteria selection for example if we select A5 = X|X|2 So Criteria1:=X, Criteria1:=X, Criteria1:=2
Filter selection would be as shown below
AutoFilter Field:=2, Criteria1:=X
AutoFilter Field:=5, Criteria1:=X
AutoFilter Field:=7, Criteria1:=2


Book1
A
1P2|P5|P7
2X|1|X
32|2|X
41|1|1
5X|X|2
61|2|1
72|1|2
81|1|2
92|X|1
10X|1|2
11X|2|1
122|2|1
131|X|X
142|2|2
151|1|X
161|X|1
Sheet2


This filter will make life easier

Please help

Regards,
Kishan
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,302
Members
449,150
Latest member
NyDarR

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