Query my excel worksheet with VBA

天涯浪子 提交于 2019-11-26 17:15:58

问题


Is it possible to query a worksheet using 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

I there any way to do this, a tutorial would be really helpful.

Thanks


回答1:


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


来源:https://stackoverflow.com/questions/18637376/query-my-excel-worksheet-with-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!