Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- 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.
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