Give your data a header, I called it DATE. Give this a try
Option Explicit
Sub FetchData()
' Need to reference Microsoft ActiveX Data Objects 2.x
Dim stSQLstring As String
Application.ScreenUpdating = False
stSQLstring = "Select Count([Date]) From " & _
"[Sheet1$] Where [Date] = #" & Format(Now, "mm/dd/yyyy") & "#" & _
";"
QueryWorksheet stSQLstring, _
Sheet1.Range("B1"), _
"C:\test\test_file.xlsx"
stSQLstring = "Select Count([Date]) From " & _
"[Sheet1$] Where [Date] <= #" & Format(Now - 2, "mm/dd/yyyy") & "#" & _
";"
QueryWorksheet stSQLstring, _
Sheet1.Range("B2"), _
"C:\test\test_file.xlsx"
stSQLstring = "Select Count([Date]) From " & _
"[Sheet1$] Where [Date] > #" & Format(Now, "mm/dd/yyyy") & "#" & _
";"
QueryWorksheet stSQLstring, _
Sheet1.Range("B3"), _
"C:\test\test_file.xlsx"
Application.ScreenUpdating = True
End Sub
Public Sub QueryWorksheet(szSQL As String, rgStart As Range, wbWorkBook As String)
Dim rsData As ADODB.Recordset
Dim szConnect As String
On Error GoTo ErrHandler
Application.StatusBar = "Retrieving data ....."
szConnect = "Provider = Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & wbWorkBook & ";" & _
"Extended Properties=Excel 12.0;"
Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not rsData.EOF Then
rgStart.CopyFromRecordset rsData
Else
MsgBox "There is no records that matches the query !!", vbCritical
End If
rsData.Close
Set rsData = Nothing
Application.StatusBar = False
Exit Sub
ErrHandler:
'an error occured in the SQL-statement
MsgBox "Your query could not be executed, the SQL-statement is incorrect."
Set rsData = Nothing
Application.StatusBar = False
End Sub