problem with VBA Filter

Mcstefan

Board Regular
Joined
May 17, 2014
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hi,

T
he VBA line below does Filter / Number Filters / Custom Filter / Begins with 1
ActiveSheet.Range(Selection, Selection.End(xlUp)).AutoFilter Field:=1, Criteria1:="1*"
and the result is nul, which is incorrect, because I was expecting to see a lot of lines that met this criteria.


However, if I manually do in Excel
click on Filter / and in the Search box I type 1*, then I get as a result a lot of lines (which is exactly what I want and what I expected to see).


Can anybody help me to correct the code or tell me why is not working

Thanks.
Cristian
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Ugly workaround...
Select your column, Click Data, Text to Columns, click Next twice, check the Text checkbox, Click Finish.
Your macro should work now but this option depends on what you are doing with the data afterwards.
 
Upvote 0
you could also put this formula in an adjacent column and filter by True/false
Change the reference in red to suit the column you are working with

Code:
=IF(LEFT([color=red]B1[/color],1)*1=1,"True","False")
 
Upvote 0
Hi Mark, is still not working, the result of the filter is still nul. After applying what you suggested, the code did Filter / Text Filters / Begins with / begins with 1 instead of previously
Filter / Number Filters / Custom Filter / Begins with 1
<strike></strike>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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