+ Reply to Thread
Results 1 to 15 of 15

I'm getting Run-time error ‘13’: type mismatch and unsure about solving.

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Red face I'm getting Run-time error ‘13’: type mismatch and unsure about solving.

    I think I have changed the title.
    Last edited by sdingman; 03-21-2020 at 01:56 PM. Reason: To change the title as requested by a moderator.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    What error code is generated if any?

    If error occurs in the line ws3... line, likely issue is data type mismatch (i.e. trying to subtract string value from numeric or vice versa).

    But it will be bit difficult for us to give you specific solution without sample workbook that replicates your issue. I'd recommend uploading sample workbook, using details outlined in the yellow banner at top.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    CK76, Thanks for replying so quickly.
    ws3 cell A2 is where I want the difference between two time stamps from ws2, column 9, I. This is why I have formatted ws3, column A to display Seconds.

  4. #4
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    CK76, you are correct I am getting Run-time error ‘13’: type mismatch.
    ws2 column I is a concatenation of a Date column and a Time column. The sampling data is time stamped every 5 seconds. So I expect the result to be a single digit 5 representing seconds, so the source and destination are custom formatted date and time. When I manually enter the formula into the destination cell it works fine. Steve

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    Concatenated date & time values are classified as string data type. When using worksheet formula, some string values can be coerced into numeric (ex: using double unary, +0, *1 etc).

    However, in VBA, left and write side of operator must be similar (i.e. date & integer, long & double etc). You cannot implicitly add string representation with numeric.

    Although I'd recommend using Date column + Time column (instead of concatenation).

    You can try below and see if it works as well...

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    I'm having trouble trying to attach my sample workbook.

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,561

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    See yellow banner

  8. #8
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,561

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  9. #9
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    This is my attempt to send a sample of my workbook.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    CK76, Thanks again. I'm sorry about not getting to the point, but I use this site so infrequently that every time I visit, its like starting all over. I think I did finally manage to send a sampling of my workbook. Now I see that you replied and said:
    Concatenated date & time values are classified as string data type. When using worksheet formula, some string values can be coerced into numeric (ex: using double unary, +0, *1 etc).
    , I had never read anything like that. I have used the difference between different times in another macro in my excel file to create my "On Period Analysis" sheet, and never got an type mismatch error.
    You are also saying, if I'm interpreting what you are saying is that, When I manually placed the formula into cell A2 to calculate the 5, that I got, because,
    When using worksheet formula, some string values can be coerced into numeric (ex: using double unary, +0, *1 etc)
    . So you mean that Excel will let me make an error when I manually enter a formula into a cell, but not when VBA places a result into a cell.
    You also suggested that I try adding,
    Please Login or Register  to view this content.
    What is CDbl?Steve

  11. #11
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    If use use date string - date string in worksheet cell (manually), it will be interpreted as datetime value - datetime value. But in VBA it is not implicitly treated as such.

    CDbl, CLng family of functions are used to convert string data type to Double, Long etc.

    In your case instead of CDbl, use CDate to convert datetime string into datetime value.

    Ex:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    CK76, I tried your suggested line of code and still got the Type Mis-match. So now since that Type conversion didn't work I think I'll pursue the column merge that you had suggested earlier. I'll let you know the result. Steve

  13. #13
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    Hmm? Worked fine on my end.

    See attached.

    As for using + method in cell.
    Replace & " " & part with + in your concatenate formula.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    11-15-2011
    Location
    St. Louis, MO
    MS-Off Ver
    Excel 2013
    Posts
    69

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    CK76, Thanks again. Your sugestion:
    In your case instead of CDbl, use CDate to convert datetime string into datetime value.
    did the trick. I'll now mark this as solved. Steve

  15. #15
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,561

    Re: I'm failing to find my error. Maybe I'm mixing my variables or misusing something.

    @CK76 and sdingman

    Administrative Note:



    Sorry, but your post does not comply with Rule #6 of our Forum RULES:

    Please do not ignore requests by Administrators, Moderators and senior forum members regarding forum rules.

    If you are unclear about the request or instruction, then send a private message to them asking for clarification.

    All Participants:

    Please do not post a reply in a thread where a Moderator or Administrator has requested an action that has not yet been complied with (e.g. title change, code tags requested, etc.). Thanks.

+ 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. [SOLVED] Failing FIND method?
    By AxiAngel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-06-2017, 08:33 AM
  2. 'While' function inside of error handler giving an error/failing
    By dnwadams in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2015, 12:18 AM
  3. Failing to find a value. New to VBA
    By bmcmvp in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-14-2015, 01:09 PM
  4. [SOLVED] .find Function Failing
    By Centexcel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-26-2013, 11:36 AM
  5. =sumif() giving VALUE# error when mixing sheet references
    By pickslides in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-04-2009, 01:58 AM
  6. Cell.Formula failing with single & double variables
    By EseKuent in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2009, 02:36 AM

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