vba 带有选项“开始于”的过滤器编号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27937337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Filter number with option "begins with"
提问by kobebryant
Can we filter number in excel with option "begins with", when I filter at the box "search" of combobox ex: 15*. It's ok, but in Number Filters/Custom Filters I use "begins with" it didn't work. I try to record Macro with the way "search" in combobox for the code but it is impossible.
当我在组合框的“搜索”框过滤时,我们可以使用选项“开始于”过滤数字,例如:15*。没关系,但是在数字过滤器/自定义过滤器中,我使用“开头为”它不起作用。我尝试使用组合框中的“搜索”方式记录宏以获取代码,但这是不可能的。
How to write VBA code for this. Thank you, this is the macro recorded.
如何为此编写 VBA 代码。谢谢,这是宏录制的。
ActiveSheet.Range("$A:$AF94").AutoFilter Field:=12, Criteria1:=Array( _
"1521", "1522", "1526", "1541", "1542", "1543", "1561"),Operator:=xlFilterValues
But I wanna filter the value 15*
但我想过滤值 15*
回答by L42
Yes you are correct, that is not possible in AutoFilter.
Here's a way though if your data are numbers.
是的,您是对的,这在 AutoFilter 中是不可能的。
如果您的数据是数字,这是一种方法。
ActiveSheet.Range("$A:$AF94").AutoFilter Field:=12, Criteria1:=">=1500"
Or this if you specifically want those with 15in it.
或者如果你特别想要那些有15 个的。
ActiveSheet.Range("$A:$AF94").AutoFilter Field:=12, Criteria1:=">=1500" _
Operator:=xlAnd, Criteria2:="<1600"
Edit1:Answer to follow-up in comment
编辑 1:在评论中回答后续问题
You can change all your data into Textby using Text To Columnsunder Data Tab.
Steps:
您可以使用Data Tab下的Text To Columns将所有数据更改为Text。脚步:
- Select the entire column where you have your data in number format.
- Then click on Text To Columns. Press Nexton the 1st and 2nd dialogue box.
- On the 3rd dialogue box, select Textinstead of General.
- 选择包含数字格式数据的整列。
- 然后单击Text To Columns。在第一个和第二个对话框中按Next。
- 在第三个对话框中,选择Text而不是General。
Now, all your data are in the form of text.
You can then use below code to filter all that begins with 15.
现在,您的所有数据都采用文本形式。
然后,您可以使用以下代码过滤所有以15开头的内容。
ActiveSheet.Range("$A:$AF94").AutoFilter Field:=12, Criteria1:="15*"