Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query my excel worksheet with VBA

Is it possible to query a worksheet using VBA?

data table

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

like image 531
cwiggo Avatar asked Oct 04 '22 01:10

cwiggo


1 Answers

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
like image 167
Joe Avatar answered Oct 12 '22 07:10

Joe