Results 1 to 15 of 15

Thread: Date Type Mismatch

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Date Type Mismatch

    This just started happening out of the blue. I believe the Excel Data is a date...

    Type Mismatch Error 13 on this line:
    Code:
    startdate = ThisWorkbook.ActiveSheet.Cells(i2, 10).Value
    Code:
                Dim startdate As Date
                If Len(ThisWorkbook.ActiveSheet.Cells(i2, 10).Value) > 0 Then
                    startdate = ThisWorkbook.ActiveSheet.Cells(i2, 10).Value
                
                End If
    Thanks!
    - A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Date Type Mismatch

    Quote Originally Posted by ssabc View Post
    This just started happening out of the blue. I believe the Excel Data is a date...
    Debugging is the act of comparing your belief against reality.

    Good luck.

  3. #3
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Date Type Mismatch

    You have "i"2 instead of 12
    HTH

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Re: Date Type Mismatch

    i2 is the row number, 10 is the column. That is where the dates are located. In debug, it shows a date! But says its the wrong data type.
    Last edited by ssabc; Nov 10th, 2020 at 01:19 PM.
    - A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!

  5. #5
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: Date Type Mismatch

    What happens if you try this:

    Code:
    startdate = CDate(ThisWorkbook.ActiveSheet.Cells(i2, 10).Value)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Re: Date Type Mismatch

    Oh I've tried that! Same issue
    - A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!

  7. #7
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Date Type Mismatch

    Quote Originally Posted by ssabc View Post
    i2 is the row number, 10 is the column. That is where the dates are located. In debug, it shows a date!
    What, exactly, does it show? Note that something like "November 10, 2020" is a date to the human eye, but to a computer it is a String and not a Date value.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Re: Date Type Mismatch

    Quote Originally Posted by OptionBase1 View Post
    What, exactly, does it show? Note that something like "November 10, 2020" is a date to the human eye, but to a computer it is a String and not a Date value.

    11/20/2020. The format is in fact, correct.
    - A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!

  9. #9
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Date Type Mismatch

    Well, I just did some limited testing and pointed identical code to what you posted at different cells formatted as a Date, Text, preceded with a ', etc with a date of 11/10/2020 and couldn't get it to fail.

    Without further details (like an example spreadsheet that exhibits the behavior reported), the next most logical conclusion is that the cell you think it is referencing isn't the cell that is actually being referenced.

    I can't assist further. Good luck.

  10. #10
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: Date Type Mismatch

    What do you get with this code:

    Code:
    Debug.Print ThisWorkbook.ActiveSheet.Cells(i2, 10).Value

  11. #11
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Date Type Mismatch

    Going back to my post #3.

    A Cell takes a reference of Cell(row, column).
    Excel used to refer to rows by numbers (1 to ...) and columns by Letters (A, B, C, ....)
    So a single Cell reference would be something like Cell(12, K) -- or 12K without the Keyword Cell
    I've never seen a single row referenced as a letter number combination such as i2

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Date Type Mismatch

    vb6, have you considered that i2 is probably a numeric variable that is being used to do something like loop through rows?

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Date Type Mismatch

    That blasted "Active"-Something again.
    Is your "Active"-Sheet even the "correct" one?
    Does the error happen, when you qualify the sheet directly (via number/Name)?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Date Type Mismatch

    try dimensioning startdate as a variant, step through the code to that line (or put a break point) then in the locals window you will be able to look at the variable to see what type visual basic thinks it should be and whether the value it has, matches what you expect
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    858

    Re: Date Type Mismatch

    OptionBase1:
    vb6, have you considered that i2 is probably a numeric variable that is being used to do something like loop through rows?
    My Error -- Thanks for pointing it out. I use variables all the the time for row or column, but for whatever reason never made the connection "i2" could be a row variable, maybe because of the hardcoded "10"

Posting Permissions

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



Click Here to Expand Forum to Full Width