vba filter exact match

amelia123456

New Member
Joined
Apr 15, 2019
Messages
8
I have a few locations, eg. AMK, AMK MRT.

When i type AMK, both amk and amk mrt will appear, how do i filter to exact when i type amk, only amk will appear?



this is my code

Sub Advanced_Filtering()


Range("A8:H1611").AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Range("A1:C2")


End Sub





codeassetslocation filter(this is a button)
AMK
Codedatecostassetsownerconditionlocation
1234512/02/20162000sealing machineabcgoodAmk
2245610/05/20171000sugar machineabcgoodAmk Mrt
5562411/04/20181800induction cookerabcgoodAMK

<tbody>
</tbody>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Upvote 0
Try

Code:
Sub Advanced_Filtering()
    Dim strCriteria As String
      
    strCriteria = "AMK"
    Range("C2") = "=""=" & strCriteria & """"
        
    If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
    
    Range("A8").CurrentRegion.AdvancedFilter _
        Action:=xlFilterInPlace, CriteriaRange:=Range("A1:C2")
End Sub

M.
 
Upvote 0
Please do the following:
- Change the format of cell C2 to general format. (This is very important)
- Write in the cell C2 the Amk data without quotes or spaces, only the Amk data


That should look like this:

a833773ce982995d29d8cedf66cc4214.jpg




- Execute the following code

Code:
Sub Advanced_Filtering()
    If InStr(1, Range("C2").Value, "=") = 0 Then
        Range("C2").Formula = "=""=" & Range("C2").Value & """"
    End If
    Range("A8:H1611").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("A1:C2")
End Sub
 
Upvote 0
Hi Dave,

it does not work, whenever i click on the filter button, "" will appear continuously and results will not appear.

Hi,
sorry about that, my bad should have thought about blank entry

try this update which includes the other filter criteria headings you have in the range

Code:
Sub Advanced_Filtering()
    Dim strCriteria As String
    Dim cell As Range
    
    For Each cell In Range("A2:C2")
        If Len(cell.Text) > 0 Then
        strCriteria = cell.Text
'ensure = sign not already included
        strCriteria = Replace(strCriteria, "=", "")
'add = sign to formula
        cell.Formula = "=""=" & strCriteria & """"
        End If
    Next cell
'reset filter
    If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
'apply filter
    Range("A8").CurrentRegion.AdvancedFilter _
    Action:=xlFilterInPlace, _
    CriteriaRange:=Range("A1:C2")
End Sub

Hope helpful

Dave
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

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