+ Reply to Thread
Results 1 to 31 of 31

Debug error 13

  1. #1
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Debug error 13

    I have a working Excel 2007 macro that accesses two worksheets. I then added a third worksheet and want to access it from the macro. I get a debug error 13 Type Mismatch when the macro tries to access the third worksheet. I know I need to add the third worksheet on a pop-up but I don't remember how to open it. Help!!!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Debug error 13

    Welcome to the forum.

    I know I need to add the third worksheet on a pop-up ...
    Pardon?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    Were you asking about my reference to a pop-up?

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    That confused me too. What code actually triggers the error though?
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    The error is triggered when the third worksheet is referenced. If I coment out the third Gosub the macro works. When I added the second sheet I found a way to add a worksheet but I can't remember it or find it now . The way included selecting something in the project window and typing a Cntl and another key. This brought up a window that allowed me to add the worksheet.

    I had to shorten my code to include it here:

    Please Login or Register  to view this content.
    Last edited by BillGoodman; 06-23-2009 at 10:51 AM.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    You shouldn't get a type mismatch error if the sheet doesn't exist, you should get a subscript out of range. However, you are looking for sheets 1, 3 and 5 so you'll need more than 3 sheets anyway. Can't you just add them through the user interface by clicking the new sheet button?
    I have no idea why you are using GoSub either which is somewhat outdated and makes for unnecessarily convoluted code.

  7. #7
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    The use of the Gosub is out of habit.

    Worksheets 1, 2, 3, 4, 5, and 6 are defined. I had the macro working worksheets 1 and 2. Then I added 3 and 4. I had the same problem, but I found a way in one of the help pages to configure the macro to accept 3 and 4 and it worked. Now I've added 5 and 6 and can't remember what I did to fix it before. I guess I'm having a Senior Episode.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    You still didn't say which line actually triggers the error. If it's this one:
    Please Login or Register  to view this content.
    then you probably have an error value in that cell.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Debug error 13

    Bill,

    Please take a few minutes to read the forum rules, and then edit post#5 to add code tags.

  10. #10
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    Please Login or Register  to view this content.
    Last edited by BillGoodman; 06-23-2009 at 10:52 AM.

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    See my last post then - sounds like there is an error in that cell.

  12. #12
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    There is an error in the rangetopoke. How can I clear it? Worksheet 5 is in the Workbook, the macro doesn't acknowledge it.
    Last edited by BillGoodman; 06-23-2009 at 10:54 AM.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    You could add an error handler to the code - for example:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    The error is due to sheetNumber being set to 5.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    No, it's not. It's due to there being an error value in that cell, otherwise the error would not occur on that line.

  16. #16
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    The cell contains a value of 65535. The same cell on worksheets 1 and 3 contain 65535.

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    If, as you said, this line is causing a type mismatch error:
    Please Login or Register  to view this content.
    then the value can't be 65535. Are you sure you are checking the right sheet? What do you get if you add this line before that one:
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    There is an Error 2042 in rangeToPoke when that line is executed with sheetNumber = 5.

  19. #19
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    So did you add the error check I suggested?

  20. #20
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    With your suggested code added I get the "Debug Error 13 Type Mismatch" error when it is executed. I added a watch for rangeToPoke, rangeToPoke.Value, and sheetNumber. After the error occurs they contain the following:

    rangeToPoke: Error 2042
    rangeToPoke.Value: Error 2042
    sheetNumber: 5

  21. #21
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    Can you post the current code you have, just so I can check it?

  22. #22
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Debug error 13

    Bill,

    Are you attempting to reference a worksheet named "5", or Worksheets(5)?

  23. #23
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    Please Login or Register  to view this content.

  24. #24
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    So you didn't add the error handler I suggested earlier?

  25. #25
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    I am attempting to access the 5th worksheet (Sheet5). Worksheets(5).
    Last edited by BillGoodman; 06-23-2009 at 12:26 PM.

  26. #26
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    I did add the error handler and I got a Run-Time Error 424 Object Required. I have been trying some things and I took it out along the way.

  27. #27
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    I don't see how you could get a 424 error with what I posted - where exactly did you put it?

  28. #28
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    Just above the MsgBox line.

  29. #29
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    This code works:

    Please Login or Register  to view this content.
    This uses the names of the sheets instead of the numbers.

  30. #30
    Registered User
    Join Date
    06-22-2009
    Location
    Greenville, Texas
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Debug error 13

    RomperStomper,

    Thanks for your help!

  31. #31
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Debug error 13

    No problem - glad you got it fixed!

+ 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