Autofilter - Criteria To Find Only Part Of A Match

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I've come across a problem with the use of a worksheet autofilter that I can't figure out how to approach.

I wish to filter my worksheet based on the data found in column B. The data in column B all take on the same format ##########AAA####. The first five numbers are the serial number of a date, the next 5 numbers are an employee number, followed by a 3 letter code, followed by a two digit program number and finally a two digit record id. In any series there could be any number of record ids.

I need to filter based on the value in column B minus the last two digits. For example, the criteria will be 4916531286WUP08. I need the filter to filter all values in column B that start with this value. This essentially will reveal all the record IDs for that series. What I have below, if inqtofind = 4916531286WUP08, the filter will fail because it isn't representative of the data in column B.

Code:
With ws_sdata
            If .AutoFilterMode = True Then .AutoFilterMode = False
            lrow = .Cells(.Rows.Count, "B").End(xlUp).Row
            Set filter_rng = .Range("A2:AZ" & lrow)
            .Range("A2").AutoFilter Field:=2, Criteria1:=inqtofind
            For Each rw In filter_rng.SpecialCells(xlCellTypeVisible)
            '
           Next rw
End With
 

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)
Assuming inqtofind is set to "4916531286WUP08"
Then
.Range("A2").AutoFilter Field:=2, Criteria1:=inqtofind

would be changed to something like
.Range("A2").AutoFilter Field:=2, Criteria1:=inqtofind & "*"
 
Upvote 0
Solution
Thank you Johnny, that was very helpful and appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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