Filtering on String Length

K

Keith Wilby

What VBA code would I need to set a filter based upon string length in a
cell, for example, if I wanted to filter column A for those entries 8
characters in length?

I found this in the help:

Worksheets("Sheet1").Range("A1").AutoFilter _
field:=1, _
Criteria1:="Otis"
VisibleDropDown:=False

but I don't know how adapt that for my needs. I guess I need to use the Len
function somewhere in there.

A little background - I am creating and formatting the spreadsheet from
within MS Access.

Many thanks.
Keith.
 
G

Guest

in an adjacent column, but in the formula

M2: =len(B2)

Range("M2:M200").Formula = "=Len(B2)"

then apply your filter to column M.
 
R

Ron Coderre

Perhaps something like this?:

Worksheets("Sheet1").Range("A1").AutoFilter _
field:=1, _
Criteria1:="????????", _
VisibleDropDown:=False

Does that help?
--------------------------

Regards,

Ron (XL2003, Win XP)
Microsoft MVP (Excel)
 
K

Keith Wilby

Tom Ogilvy said:
in an adjacent column, but in the formula

M2: =len(B2)

Range("M2:M200").Formula = "=Len(B2)"

then apply your filter to column M.

Spot on, working a treat. Thanks Tom.

Keith.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top