cannot get it to auto filter

zakizelani

New Member
Joined
Mar 3, 2016
Messages
25
i cant seem to find whats my mistake from the code. when i do manually filter i can get the table to filter the data base on my criteria. howver when i run my vba code, it cannot filter the data with the criteria.




Code:
Sub CopyFilter()'clear the contents
    Sheet12.Range("B4:P10000").ClearContents
'copy and paste the range
    Sheet7.Range("Database").SpecialCells(xlCellTypeVisible).Copy _
    Destination:=Sheet12.Range("B4")
End Sub




Code:
Sub Between2Dates()'declare the variables
Dim DateBegin As Date
Dim DateEnd As Date
Dim Rng As Range
'set error handler
'On Error GoTo errHandler:
'stop screen flicker
Application.ScreenUpdating = False
'set the variables
Set Rng = Sheet7.Range("B8")
DateBegin = Format(Sheet12.Range("B2").Value, "mm/dd/yy")
DateEnd = Format(Sheet12.Range("C2").Value, "mm/dd/yy")
'check the dates if all is OK run the filter
If Sheet12.Range("B2").Value >= Sheet12.Range("C2").Value Then
MsgBox " Your start value is wrong"
Exit Sub
Else
If Not IsEmpty(DateBegin) And Not IsEmpty(DateEnd) Then
'run the filter
With Rng
.AutoFilter Field:=3, Criteria1:=">=" & DateBegin, _
Operator:=xlAnd, Criteria2:="<=" & DateEnd


                                                                            
'copy values
CopyFilter
'show all data
Showall
End With
End If
End If
'error block
'On Error GoTo 0
Exit Sub


'errHandler:
MsgBox "There is no data"
Showall




End Sub
 
My question is, when you look at the filter, it it exactly the same as when you apply the filter manually?

And when you filter the data manually, it works? (to verity it's not your dates causing problems)

yes, the filter put on the correct date is just like it didnt press okay
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
If you put a workbook on box.net that minimally illustrates the problem and post a link, I'll take a look.
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,131
Members
449,206
Latest member
burgsrus

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