+ Reply to Thread
Results 1 to 20 of 20

Run time error '13' - type mismatch

  1. #1
    Registered User
    Join Date
    06-24-2011
    Location
    ENGLAND
    MS-Off Ver
    Excel 2007
    Posts
    39

    Run time error '13' - type mismatch

    Hello

    I've posted this same question in another forum, but got no responses, I'm hoping someone here can help me!

    I have the run time error '13' type mismatch problem on the line that I have bolded. I think I understand why the problem occurs, I just don't know how to solve it.

    What is really annoying about it all is that we don't get the error in Excel 2007 at all until the file is sent in an email, used in Excel 2010, and when it's sent back to be used in Excel 2007 again, the problem arises. I have to then revert to the backed up original '07 file before it was sent in the email.

    Basically, this spreadsheet is used to send text messages to numbers in certain columns. If the relevant cell is empty, this error handler kicks in to collect a number from the user.

    Code:

    Please Login or Register  to view this content.
    Is there a code solution with the whole Excel 2007/2010 problem?

    Any help you could give would be amazing.
    thanks!
    Last edited by a8747; 05-18-2012 at 05:20 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run time error '13' - type mismatch

    Have you tried with the simple Inputbox alone instead of the Application.Inputbox?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-24-2011
    Location
    ENGLAND
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Run time error '13' - type mismatch

    Hello Arlette,
    I've just tried that and got no joy. Same error.
    thx

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    You are using:

    Please Login or Register  to view this content.
    and then

    Please Login or Register  to view this content.
    I think you meant to use a worksheet not a button since buttons don't have ranges.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Registered User
    Join Date
    06-24-2011
    Location
    ENGLAND
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Run time error '13' - type mismatch

    Abousetta,
    Forgive my inexperience, but what do I need to be doing then with the
    Please Login or Register  to view this content.
    line?

    If I simply get rid of it along with the relevant 'end with' further down , I get an 'object variable with block variable not set' error.

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    On the contrary, you need another With... End with and tell it which sheet to look into for this range.

    Or you can hard code the sheet name before every .Range.

    Buttons don't have a range property and that's why when you ask vba to look at

    ActiveSheet.Buttons(MyButton).Range it will give you an error.

    If you could post a sample workbook, I can have a look.

  7. #7
    Registered User
    Join Date
    06-24-2011
    Location
    ENGLAND
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Run time error '13' - type mismatch

    Ok, I've attached an example of what the spreadsheet is like and does. Each button at the end of each row opens Outlook and builds an email from the contents of the cells in the respective row.

    Column O links to a database of phone numbers which is used in the 'to' field of Outlook. If the number is missing from column O, the error handler kicks in to collect a number from the user which is then used by Outlook and also stored in column N. It's the error handler that doesn't work.

    I've had to remove and relabel everything for security reasons. Annoyingly, I now get a 'run time error: overflow' since I altered things for internet publication. The problem is on the same line of code in the error handler though.

    The relevant coding sits in module 3.

    Thanks!sample worksheet.xlsm

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    Hi,

    OK. Got it working now (on my system at least ). I also made some adjustments to streamline things a bit. Let me know if you need anything else.

    abousetta

    Please Login or Register  to view this content.

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '13' - type mismatch

    I reckon your problem is down to the button moving slightly so that the topleftcell and bottomrightcell are no longer the same. when that happens you are trying to compare an array of values to 0 which won't work. do you really need to refer to bottomrightcell as well? I'd rather replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    or use the bottomrightcell if you prefer. better yet would be to not use buttons at all and use a worksheet event such as selectionchange or a double-/right-click
    Last edited by JosephP; 05-18-2012 at 12:01 PM.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  10. #10
    Registered User
    Join Date
    06-24-2011
    Location
    ENGLAND
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Run time error '13' - type mismatch

    abousetta, interesting stuff thanks. I notice that it doesn't entirely work as planned. If the number does exist in column O, the email that is created doesn't take it and put it into the 'to' field in Outlook. I alter the code to correct it but get the 'type mismatch' issue again, this time on the strTo code.
    Any ideas? thx

    JosephP, I'm not sure how to get the
    Please Login or Register  to view this content.
    to work. Any tips would be brill.

    thx

  11. #11
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    Try this:

    Please Login or Register  to view this content.
    Personally I like using Select Case instead of multiple If statements but you can do it either way. In all cases, should be working now. My other advice to you is to change your programming style by removing "On Error GoTo" and rather specify what the error would look like and quantify it like I did in this example. That way other errors can be captured. Right now all errors will assume that the number is #NA, but it could be something completely different (e.g. different sheet names, etc.).

    Let me know if you have any questions.

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '13' - type mismatch

    I would suggest something like
    Please Login or Register  to view this content.
    this is not tested though!

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '13' - type mismatch

    abousetta,
    your error handler will not work if an error occurs within it or occurs after the goto statement. you can only reset an error handler with a resume statement or by exiting the routine.

  14. #14
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    HI Joseph,

    My point exactly. I was attempting to provide a well-rounded solution to error trapping but rather trap only errors in column with #NAs. I agree that this is not optimal and needs a more rounded approach.

    abousetta

    P.S. Error type 13 with your posted code

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '13' - type mismatch

    how is that your point? if you have two errors of any kind, your error handler won't work because of the goto statement. it needs to be a resume statement.

  16. #16
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '13' - type mismatch

    ok commented out the Outlook bit as can't test that on Mac and see problem. small tweak
    Please Login or Register  to view this content.
    Last edited by JosephP; 05-19-2012 at 11:24 AM.

  17. #17
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    no point at all

  18. #18
    Registered User
    Join Date
    06-24-2011
    Location
    ENGLAND
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: Run time error '13' - type mismatch

    You both have a point, I've always wanted to improve the error handling in the code, namely to capture and deal with #REF! errors as well. How is the errhandler changed so that it will prevent code executing if the #REF! error exists anywhere in column O and advises the user via msgbox?

    Joseph, your code won't put the phone number the user entered in the input box into column N.

    cheers!

  19. #19
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run time error '13' - type mismatch

    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    you can use iserror to test for an error in the same row in column O or use Application.Worksheetfunction.Countif(Range("O:O"), "#REF") to test for a ref error anywhere in the column

    @abousetta
    I must apologize to you - just reread my last post and I can see that it would seem very rude. that was not my intention in any way and I'm very sorry for that. I just meant that I didn't understand what you were saying. Sorry again for any offense.
    Last edited by JosephP; 05-20-2012 at 04:19 AM.

  20. #20
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run time error '13' - type mismatch

    No worries... I will have a look again when my mind clears...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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