Date Variable to a filter table

mrtjart

New Member
Joined
Oct 17, 2016
Messages
4
When this macro runs off of a button on an excel vba form, filter does not work
>=1/1/2016
should change the filter to only show dates >= Jan 1 2016, but it does not work.
The table data comes in as a date field, but excel does not format the data as a date formate until after I refresh it and change that column to Date format from General. So the dates are in 2016-01-01 format from sql and the filter does not work.
If in SQL I change the date to a text variable as 01/01/2016 it still does not filter.

Code:
Private Sub CommandButton3_Click()
Dim msgboxAnswer As Integer
ws = ActiveSheet.Name
msgboxAnswer = MsgBox("Dates correct " & DateLeft & " " & DateRight & "?", vbYesNoCancel)
If msgboxAnswer = 6 Then
'Answer = 6(Yes)
  If ws = "Incentives Sanctions" Then
    Sheet8.ListObjects("Table_Query_Incentives_Sanctions").Range.AutoFilter Field:=3, Criteria1:=">" & DateLeft
  End If
    End If
'Debug.Print DateLeft
'Debug.Print DateRight
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
When this macro runs off of a button on an excel vba form, filter does not work
>=1/1/2016
should change the filter to only show dates >= Jan 1 2016, but it does not work.
The table data comes in as a date field, but excel does not format the data as a date formate until after I refresh it and change that column to Date format from General. So the dates are in 2016-01-01 format from sql and the filter does not work.
If in SQL I change the date to a text variable as 01/01/2016 it still does not filter.
Follow up to my own post. In SQL I changed the variable type to DATETIME. And while that is not user Friendly in excel, because all of the times are 0:00 oclock, it makes the criteria function work.
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,772
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top