+ Reply to Thread
Results 1 to 6 of 6

Type Mismatch when filtering for dates

  1. #1
    Registered User
    Join Date
    08-03-2018
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    4

    Type Mismatch when filtering for dates

    Hello friends,

    I'm trying to filter a database by month and used the codes below:

    Please Login or Register  to view this content.
    I am bit sure why but I am receiving a 'type mismatch' error when running those codes. I'm not sure why this is happening since everything is in MM/DD/YYYY format.


    Thank you so much for reading this.

    Have a nice day!

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Type Mismatch when filtering for dates

    May be


    Range("$A$2:$BF$" & Cells("A", Rows.Count).End(xlUp).Row).AutoFilter Field:=2, Operator:=xlFilterValues, Criteria2:=Array(1, Format(DateAdd("m", -1, Date), "mm/dd/yyyy"))

  3. #3
    Registered User
    Join Date
    08-03-2018
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    4

    Re: Type Mismatch when filtering for dates

    Quote Originally Posted by AB33 View Post
    May be


    Range("$A$2:$BF$" & Cells("A", Rows.Count).End(xlUp).Row).AutoFilter Field:=2, Operator:=xlFilterValues, Criteria2:=Array(1, Format(DateAdd("m", -1, Date), "mm/dd/yyyy"))
    Hi AB33,

    Thank you so much for your reply, but the problem still persists. I don't understand. The data is of the right type "e.g. 12/29/2017".

  4. #4
    Registered User
    Join Date
    08-03-2018
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    4

    Re: Type Mismatch when filtering for dates

    It looks like this is the problem: Array(1, Format(DateAdd("m", -1, Date), "mm""/""dd""/""yyyy")

    because when I try to get the value from it in the immediate window, the mismatch error appears.

  5. #5
    Registered User
    Join Date
    08-03-2018
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    4

    Re: Type Mismatch when filtering for dates

    Omg, I found out what the problem is! I used Cells("A", Rows.Count). instead of Cells(Rows.Count,"A").

    Can't believe I made such a rookie mistake and got stuck at it for so long!

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,588

    Re: Type Mismatch when filtering for dates

    No need of Format function
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Type mismatch
    By xtin0117 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2015, 04:00 AM
  2. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  3. [SOLVED] Run-type error 13 type mismatch
    By misop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2012, 04:08 AM
  4. type mismatch with dates
    By totally_stuck in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2011, 07:28 PM
  5. Type Mismatch: array or user defined type expected
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2006, 10:45 AM
  6. Type mismatch using rnge as Range with Type 8 Input Box
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-03-2005, 01:10 AM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1