VBA Autofilter for non-numerical data

Dobster25

New Member
Joined
Nov 18, 2011
Messages
39
Good Afternoon peeps,

I have been trying to find a solution to my little problem. I have an autofilter however I can't get it to filter the data which is basically text only.

The numerical data in the selected column is 5 digits long (#####). I want the autofilter to select and show everything else that is not 5 digits long. Hope that makes some sense.

This is what i have so far with regards to my code:

Code:
With wBook1.Sheets("T900 Sorted")
        .AutoFilterMode = False
    End With
 
    With wBook1.Sheets("T900 Sorted").Range("A1:R1")
        .AutoFilter
        .AutoFilter field:=2, Criteria1:="<>*#####*"
    End With
 
    wBook1.Sheets("T900 Sorted").AutoFilter.Range.Copy wBook1.Sheets("T900 Unknown").Range("A1")
 
    wBook1.Sheets("T900 Sorted").AutoFilterMode = False

Hopefully this is just a quick and simple fix.

Thanks for taking your time to help me.

Kind Regards
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I think you will need to use a helper column if you want to use autofilter. Either that or loop through the column checking the length of cell values and hide the rows.

Dom
 
Upvote 0
Firefly,

Yes i have numerical data in the column.

Domski,

With regards to a helper column, is there a way to say, loop through the data and place the number '2' in the helper column? Do you know any code from the top of your head for this? Im thinking somethine like:

Code:
Lastrow = .usedrange.rows.count
 
for i = 2 to Lastrow
with range("B" & i)
       if .value = [COLOR=red](not sure how to declare numerical length)[/COLOR] then range("S" & i).value = 2
end with
next i

DO you think you can help me with the criteria?
 
Upvote 0
Firefly,

That works a treat!! thank you.

Could you please explain what each of those criterion represent please so that I and other who view this thread can understand how it works.

Thank you again to you both for your contribution.

10/10 as always.
 
Upvote 0
Sure:

Criteria1 ("=*") is a text filter for "one or more of any characters" - so it filters non-zero length text entries. Numeric entries are excluded.

Criteria2 ("=") is a blanks filter so it returns zero-length entries.

So numbers are excluded (error values would be too, if you have any), but everything else returned.
 
Upvote 0
Wow,

I have to be honest that has to be one of the most powerful filtering tools I have experienced using VBA.

Thank you again for your help!
 
Upvote 0
Hi folks! way after the fact here, but how might one do the opposite? Remove all Text from a column with some cells as numbers and some with text? I need to get a list of all unique numbers (not text).

Sure:

Criteria1 ("=*") is a text filter for "one or more of any characters" - so it filters non-zero length text entries. Numeric entries are excluded.

Criteria2 ("=") is a blanks filter so it returns zero-length entries.

So numbers are excluded (error values would be too, if you have any), but everything else returned.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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