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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,
welcome to the forum

To extract only the records for AMK, try using the following format in your criteria:

= "=AMK"


Dave
 
Upvote 0
Hi Dave,

Is there any other ways of coding it instead of putting an "=" sign?

Sorry not sure I follow you, you stated wanted an exact match which normally requires the "=" sign to be included in the critieria.

perhaps further explain your reasoning & I or others here may be able to help you further.

Dave
 
Upvote 0
Hi Dave,

Is it possible to include the = sign into the code instead of typing it whenever i'm looking for that specific criteria.

Thank you.
 
Upvote 0
Hi Dave,

Is it possible to include the = sign into the code instead of typing it whenever i'm looking for that specific criteria.

Thank you.


If you mean you manually enter your filter value in cell C2 & then have code add "=" for you, then try this


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


Dave
 
Upvote 0
open
On the picture attached, when i key in AMK in the location box, both amk and amk mrt results will appear.

In the previous reply, you mention to manually include the '=' (equal) sign, it helps.

But i would like to know if there is any other ways to get the result of 'AMK' without manually input the equal sign ?

https://drive.google.com/open?id=1VbwQaE-UrRMdoPv5LCV5-ab5S1xSCG6x
 
Upvote 0
open


But i would like to know if there is any other ways to get the result of 'AMK' without manually input the equal sign ?

My updated code in #post 7 should do insert the "=" sign for you

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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