I only use filter for dates i.e. get alarms (or Data) from date to date as below
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=BScada;UID=BRMS;Trusted_Connection=Yes;APP=Microsoft® Query;WSID=LEN_HOME;DATABASE=BScada;" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT FIXALARMS.ALM_TAGNAME, FIXALARMS.ALM_TAGDESC, FIXALARMS.ALM_VALUE, FIXALARMS.ALM_DESCR, FIXALARMS.ALM_ALMAREA, FIXALARMS.ALM_OPNAME, FIXALARMS.ALM_OPFULLNAME, FIXALARMS.ALM_DATELAST, FIXALARMS." _
, _
"ALM_TIMELAST, FIXALARMS.ALM_DTLAST" & Chr(13) & "" & Chr(10) & "FROM BScada.dbo.FIXALARMS FIXALARMS" & Chr(13) & "" & Chr(10) & "WHERE (FIXALARMS.ALM_DATELAST>='27/04/06' And FIXALARMS.ALM_DATELAST<='28/09/06')" & Chr(13) & "" & Chr(10) & "ORDER BY FIXALARMS.ALM_DATELAST, FIXALARMS" _
, ".ALM_TIMELAST")
.Name = "Query from BScada"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
as you can see the where statement gets data from a date to a date, you can substitute the fixed date (and time) with a variable dates selected from a date picker (maybe a calendar control).
Most of the data collected on my sheets is done by shift patterns when you create the macro & get external data select the fields you wish to get, the dates to start from & end with etc. the code in the macro can be copied into your routine & modified to suit, if you return data to say Sheet 3 then manipulate the data in VB i.e. copy data required to sheet 2 & use the data in sheet 1 as graphs etc.
You have to be careful with hard returns in sql the above code may have been formated differently when pasted into this editor.
I'm not at work at the moment so only have resources on my home pc but If I can I will post an excel project with a real system however you will not be able to run it as there will be no DB.