advanced filter exact match using vba

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I'm using advanced filter in a sheet using a list of clientsIDs grabbed from the same sheet. The code works, but a problem arises when I have 2 clientsIDs that start with the same numbers. For example, if one of the clients in my list is 102, my filter also includes 1021. Is there a simple way to adapt the code below to filter exact values from the clientID list? Thanks!

I searched and found that I can use this formula (
="=102" ) in ws.Range("M5")
But I don't know how to use it in my code below using "Me.cmb_ID.Value" instead of "102"

As this:
ws.Range("M5") = (="=Me.cmb_ID.Value")

Code:
[/FONT][/COLOR]ws.Range("M5") = Me.cmb_ID.Value
    ws.Range("A4").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=ws.Range( _
        "Criteria_ClientID"), CopyToRange:=ws.Range("Extract_ClientID"), Unique:=False
[COLOR=#242729][FONT=Arial]
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
In the Criteria range, if the cell holds "x" (no quotes) it will find any record where that field starts with "x". To find an exact match for x, the criteria cell should hold "=x" (no quotes)
 
Upvote 0
Seems to be the day for this question. You could use:

Code:
 With ws.Range("M5")
.Numberformat = "@" ' set Text format
.Value = "=" & Me.cmb_ID.Value
end with
 
Upvote 0
Exactly, but my main inquiry is how to use this formula in my code to get the criteria cell =102
 
Upvote 0
Thank you so much RoryA, that's what I need

Thank you so much Mike for your time
 
Upvote 0
Glad we could help.
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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