使用 VBA 查询我的 Excel 工作表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18637376/
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
Query my excel worksheet with VBA
提问by cwiggo
Is it possible to query a worksheet using VBA?
是否可以使用 VBA 查询工作表?
I want to be able to select all the values in the time column i.e. (00:00) WHERE the day equals for example: Saturday
我希望能够选择时间列中的所有值,即 (00:00) WHERE the day equals for example:Saturday
I there any way to do this, a tutorial would be really helpful.
我有什么方法可以做到这一点,教程会非常有帮助。
Thanks
谢谢
采纳答案by Joe
You can programmtically create an AutoFilter, then select the matching values:
您可以以编程方式创建自动筛选器,然后选择匹配的值:
Dim ws As Worksheet: Set ws = ActiveSheet
With ws
.AutoFilterMode = False
.Range("1:1").AutoFilter
.Range("1:1").AutoFilter field:=2, Criteria1:="=Saturday", Operator:=xlAnd
With .AutoFilter.Range
On Error Resume Next ' if none selected
.Offset(1).Resize(.Rows.Count - 1).Columns(2).SpecialCells(xlCellTypeVisible).Select
On Error GoTo 0
End With
.AutoFilterMode = False
End With