Macro needed to filter a range

cra5hdown

New Member
Joined
Oct 4, 2016
Messages
19
Have a look at the attached.

Essentially, i am unable to house in a table due to spec. and need to filter based on two inputs.

Range is Check_table - A17:H163
Filter 1: Cell H9, the concept. based on a choice here the Range needs to be filter on Col B.
for example, if 'n' is chosen, filter out (hide) all rows in the range where 'n' does not appear in the Col, the chosen letter could be within 3 letters, eg 'ent'

Filter 2: Cell E10, the type. based on a choice here the Range needs to be filtered further, in the same way, on Col C. (D - detailed, C - close, V - visual)

For both filters, the option 'Unspecified' should show all rows.
The order should always be the Col 1 of Range, the Ref.
Though Col 4 may look repetitive, the refs (eg 'A01') are unique based on Concept. (more detail will be added later)
Sheet Cols ABC will be hidden later

Thank you for your assistance.
Excel 365

HAI.xlsx
ABCDEFGH
1
2
3
4
5
6
7
8
9Concepti
10TypeDetailed
11
12
13
14Comments:
15
16Hidden
17RefConceptTypeCheck Completed:Result
181entDCVSECTION A: GENERAL - ALL EQUIPMENT
192entDCVA01
203entDCA02
214entDCA03
225entDCA04
236entDCVA05
247entDA06
258entDCVA07
269entDCVA08
2710entDA09
2811entCVA10
2912entDCVA11
3013entDA14
3114entDA15
3215entDA17
3316entDA18
3417entDA19
3518entDA20
3619entDA21
3720entDA22
3821entDA23
3922entDA24
4023entDCA25
4124entDCVA26
4225entDCVA27
4326entDA28
4427entDCVA29
4528entDCVA30
4629entDA31
4730entDCVSECTION B: INSTALLATION
4831entDB01
4932entDCVB02
5033entDCVB03
5134entDB05
5235entDCVB06
5336entDB07
5437entDB08
5538entDB09
5639entDB10
5740entDB11
5841entDCB13
5942entDB23
6043entDCVSECTION C: ENVIRONMENT
6144entDCVC01
6245entDCVC02
6346entDC03
6447inDCVSECTION A: GENERAL - ALL EQUIPMENT
6548inDCVA01
6649inDCA02
6750inDCA03
6851inDCA04
6952inDCA05
7053inDCA06
7154inDCA07
7255inDCA08
7356inDA09
7457inDCVA10
7558inDA11
7659inCVA12
7760inDCVA13
7861inDA14
7962inDA15
8063inDA16
8164inDCA17
8265inDCVSECTION B: INSTALLATION
8366inDB01
8467inDB02
8568inDCVB03
8669inDCVB04
8770inDB05
8871inDB06
8972inDB07
9073inDB08
9174inDB09
9275inDB10
9376inDB11
9477inDB12
9578inDB13
9679inDCVSECTION C: ENVIRONMENT
9780inDCVC01
9881inDCVC02
9982dDCVSECTION A: GENERAL - ALL EQUIPMENT
10083dDCVA01
10184dDCA02
10285dDCVA05
10386dDA06
10487dDCVA07
10588dDCVA08
10689dDA09
10790dCVA10
10891dDCVA11
10992dDCVA12
11093dDA13
11194dDA14
11295dDA15
11396dDCA16
11497dDCA25
11598dDCVA27
11699dDA28
117100dDCVA29
118101dDCVA30
119102dDA31
120103dDCVSECTION B: INSTALLATION
121104dDB01
122105dDCVB02
123106dDCVB03
124107dDB04
125108dDB05
126109dDCVB06
127110dDB07
128111dDB08
129112dDB09
130113dDB10
131114dDB11
132115dDCVB12
133116dDCB13
134117dDCVSECTION C: ENVIRONMENT
135118dDCVC01
136119dDCVC02
137120dDCVSECTION A: GENERAL - ALL EQUIPMENT
138121dDCVA01
139122pDCA02
140123pDCA03
141124pDA04
142125pDCVA05
143126pDCVA06
144127pDA07
145128pCVA08
146129pDA09
147130pDCVSECTION B: INSTALLATION
148131pDB01
149132pDCVB02
150133pDCVB03
151134pDB04
152135pDB05
153136pDB06
154137pDB07
155138pDCVB08
156139pDCVB09
157140pDCVB10
158141pDB11
159142pDB12
160143pDB13
161144pDCVSECTION C: ENVIRONMENT
162145pDCVC01
163146pDCVC02
Main
Cells with Data Validation
CellAllowCriteria
E10ListInitial, Visual, Close, Detailed, Unspecified
H9Listh,d,e,i,m,n,p,s,t,Uncertified Equipment, Unspecified
H19:H46ListFail, Limitation, N/A, N/C, Pass
H48:H51ListFail, Limitation, N/A, N/C, Pass
H65:H81ListFail, Limitation, N/A, N/C, Pass
H83:H95ListFail, Limitation, N/A, N/C, Pass
H97:H98ListFail, Limitation, N/A, N/C, Pass
H135:H136ListFail, Limitation, N/A, N/C, Pass
H138:H146ListFail, Limitation, N/A, N/C, Pass
H148:H160ListFail, Limitation, N/A, N/C, Pass
H162:H163ListFail, Limitation, N/A, N/C, Pass
H100:H119ListFail, Limitation, N/A, N/C, Pass
H121:H133ListFail, Limitation, N/A, N/C, Pass
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
See if this comes close to what you're looking for.

VBA Code:
Option Explicit
Option Compare Text
Sub cra5hdown()
    Dim ws As Worksheet
    Set ws = Worksheets("Main")
    Dim r As Range
    Set r = ws.Range("A17:H" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
   
    Dim s1 As String, s2 As String
    If ws.Range("H9") = "unspecified" Then s1 = "<>" Else s1 = "*" & ws.Range("H9") & "*"
    If ws.Range("E10") = "unspecified" Then s2 = "<>" Else s2 = "*" & Left(ws.Range("E10"), 1) & "*"
   
    With r
        .AutoFilter 2, s1
        .AutoFilter 3, s2
    End With

End Sub
 
Upvote 0
Solution
See if this comes close to what you're looking for.

VBA Code:
Option Explicit
Option Compare Text
Sub cra5hdown()
    Dim ws As Worksheet
    Set ws = Worksheets("Main")
    Dim r As Range
    Set r = ws.Range("A17:H" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
  
    Dim s1 As String, s2 As String
    If ws.Range("H9") = "unspecified" Then s1 = "<>" Else s1 = "*" & ws.Range("H9") & "*"
    If ws.Range("E10") = "unspecified" Then s2 = "<>" Else s2 = "*" & Left(ws.Range("E10"), 1) & "*"
  
    With r
        .AutoFilter 2, s1
        .AutoFilter 3, s2
    End With

End Sub
It doesnt automatically filter based on selections in H9 & E10, however, it does do what im looking for enough!

Thank you!
 
Upvote 0
I didn't see in your original post where you said you wanted it to filter "automatically", however, if that's what you were looking for, then the following Sheet code should give you what you want (y) :)

VBA Code:
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("H9,E10"), Target) Is Nothing Then
        Application.EnableEvents = False
        Dim r As Range
            Set r = Range("A17:H" & Cells(Rows.Count, "A").End(xlUp).Row)
            
            Dim s1 As String, s2 As String
            If Range("H9") = "unspecified" Then s1 = "<>" Else s1 = "*" & Range("H9") & "*"
            If Range("E10") = "unspecified" Then s2 = "<>" Else s2 = "*" & Left(Range("E10"), 1) & "*"
            
            With r
                .AutoFilter 2, s1
                .AutoFilter 3, s2
            End With
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
I didn't see in your original post where you said you wanted it to filter "automatically", however, if that's what you were looking for, then the following Sheet code should give you what you want (y) :)

VBA Code:
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("H9,E10"), Target) Is Nothing Then
        Application.EnableEvents = False
        Dim r As Range
            Set r = Range("A17:H" & Cells(Rows.Count, "A").End(xlUp).Row)
           
            Dim s1 As String, s2 As String
            If Range("H9") = "unspecified" Then s1 = "<>" Else s1 = "*" & Range("H9") & "*"
            If Range("E10") = "unspecified" Then s2 = "<>" Else s2 = "*" & Left(Range("E10"), 1) & "*"
           
            With r
                .AutoFilter 2, s1
                .AutoFilter 3, s2
            End With
        Application.EnableEvents = True
    End If
End Sub
i cant get that one to work.
However, the initial solution is probably better suited as it is for others to use - it does the job.
 
Upvote 0
i cant get that one to work.
However, the initial solution is probably better suited as it is for others to use - it does the job.
Fair enough, but it's probably where the code is placed. With sheet event code, you right click the tab name, select View Code, and place the code in the windows that appears on the right of the screen. It doesn't go in a standard module.
That aside, I'm glad it worked out for you and thanks for the feedback 👍 😀
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,073
Members
449,093
Latest member
ripvw

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