Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howso I sort a range based on partial text in a cell

Status
Not open for further replies.

PoohBear2000

Technical User
Mar 12, 2007
2
US
I have a range in which the first column holds FPDN 5xx or PDN xxx numbers. How can I filter so that I show only FPDN items, regardless of what number follows them?

This is my code at this point.

Dim R As Range, Cel As Range
Set R = Range("PDNNum")
For Each Cel In R
If Cel.Value <> "FPDN" Then _
Cel.EntireRow.Hidden = True

Obviously the "<> "FPDN" " reference does not work because the number following the descriptor is messing things up. Is there a "contains" reference I could use?

Here is a sample of the range and I need to filter out for FPDN:

FPDN 501 15-Sep-06 $800,000 Joe Black
FPDN 502 18-Sep-06 $36,000 Joe Black
FPDN 503 20-Oct-06 $40,000 Joe Black
PDN 001 15-Jan-06 $45,000 Joe Black
PDN 002 19-Jun-06 $70,000 Joe Black
PDN 003 6-Jul-06 N/A Joe Black
PDN 004 1-Aug-06 $110,000 Joe Black
 
Use the Like operator:
result = string Like pattern

In your case, I think it would be:
Code:
If !(cel.value Like "FPDN*") Then Cel.EntireRow.Hidden = True


_________________
Bob Rashkin
 
Why loop? use autofilter and the "Does Not Begin With" operator

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top