Autofilter, Error 13, Type Mismatch

jynxy

New Member
Joined
Feb 13, 2022
Messages
32
Office Version
  1. 2019
Platform
  1. Windows
Hi,

Im getting error 13 type mismatch when trying to filter dates not equal to. if i remove "<>" & it works fine. how can i filter all dates not equal to the date and delete.

VBA Code:
With .UsedRange.Columns("A:G")
                .AutoFilter Field:=5, Operator:=xlFilterValues, _
                        Criteria2:="<>" & Array(2, Format(dt2, "mm/dd/yyyy"))
                Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
                '.AutoFilter
            End With

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
For a single value it would just be:

VBA Code:
With .UsedRange.Columns("A:G")
                .AutoFilter Field:=5, Criteria1:="<>" & Format(dt2, "mm/dd/yyyy")
                Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
                '.AutoFilter
            End With
 
Upvote 0
@RoryA if i remove the Array it stops working, i assume this is because it is a date time column ?
 
Upvote 0
Yes, if there are time portions, that won't work. You'd need to use two criteria with an Or operator - one for is before the date, and one for is on or after the day after the date. So something like:

Code:
.AutoFilter Field:=5, Criteria1:= _
        "<" & Format(dt2, "mm/dd/yyyy"), Operator:=xlOr, Criteria2:=">=" & Format(dt2 + 1, "mm/dd/yyyy")
 
Upvote 0
Solution
Thank you that worked, i had that earlier but didnt consider the +1
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,952
Members
449,095
Latest member
nmaske

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