I have a 13 row range with the first row a header row and the next 12 rows filled in by a QueryTable. The query will return at most 12 rows, but possibly less. Below this range I have a totals row.
I want to hide any rows that do not have data and I'm using AutoFilter to do this. When I run the code it creates the AutoFilter but doesn't apply the criteria. If I step through the code, it works just fine. Any ideas?
Sub fillTable()
Dim strConn As String
Dim strSQL As String
Dim qt As QueryTable
Sheet15.AutoFilterMode = False
Sheet15.Range("DCRTable").ClearContents
strConn = "ODBC;DSN=MS Access Database;DBQ=<db path>;"
Set qt = Sheet15.QueryTables.Add(strConn, Sheet15.Range("DCRTable"))
qt.CommandText = <sql query>
qt.AdjustColumnWidth = False
qt.EnableRefresh = False
qt.FieldNames = False
qt.Refresh
hideEmpties Sheet15.Range("DCRTable").offset(-1).Resize(13)
End Sub
Sub hideEmpties(rng As Range)
rng.Parent.AutoFilterMode = False
With rng
.AutoFilter
.AutoFilter 1, "<>", , , False
End With
End Sub