2013-09-05 26 views
5

是否可以使用VBA查詢工作表?使用VBA查詢我的excel工作表

data table

我希望能夠在其中一天等於例如時間列,即(00:00)選擇所有的值:週六

我有什麼辦法可以做到這一點,教程將非常有幫助。

感謝

+1

使用'AutoFilter'(根據需要過濾「日」一欄,然後同時過濾「時間」欄),然後使用範圍'.SpecialCells(xlCellTypeVisible)'方法。 –

回答

4

可以programmtically創建一個自動篩選,然後選擇匹配值:

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