+ Reply to Thread
Results 1 to 31 of 31

Debug error 13

Hybrid View

BillGoodman Debug error 13 06-22-2009, 04:19 PM
shg Re: Debug error 13 06-22-2009, 04:22 PM
BillGoodman Re: Debug error 13 06-23-2009, 09:25 AM
romperstomper Re: Debug error 13 06-23-2009, 10:03 AM
BillGoodman Re: Debug error 13 06-23-2009, 10:11 AM
romperstomper Re: Debug error 13 06-23-2009, 10:22 AM
BillGoodman Re: Debug error 13 06-23-2009, 10:33 AM
romperstomper Re: Debug error 13 06-23-2009, 10:36 AM
shg Re: Debug error 13 06-23-2009, 10:38 AM
BillGoodman Re: Debug error 13 06-23-2009, 10:39 AM
romperstomper Re: Debug error 13 06-23-2009, 10:49 AM
BillGoodman Re: Debug error 13 06-23-2009, 10:52 AM
romperstomper Re: Debug error 13 06-23-2009, 10:56 AM
BillGoodman Re: Debug error 13 06-23-2009, 11:11 AM
romperstomper Re: Debug error 13 06-23-2009, 11:19 AM
BillGoodman Re: Debug error 13 06-23-2009, 11:35 AM
BillGoodman Re: Debug error 13 06-23-2009, 12:02 PM
romperstomper Re: Debug error 13 06-23-2009, 11:40 AM
romperstomper Re: Debug error 13 06-23-2009, 12:08 PM
romperstomper Re: Debug error 13 06-23-2009, 03:12 PM
  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,015

    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:

    Sub PokeCardNumbers()
        Dim channelNumber
        Dim sheetNumber
        Dim rangeToPoke
        
        channelNumber = Application.DDEInitiate("MBENET", "PLC1")
        sheetNumber = 1
        GoSub WriteData
        Application.DDETerminate channelNumber
    
        channelNumber = Application.DDEInitiate("MBENET", "PLC2")
        sheetNumber = 3
        GoSub WriteData
        Application.DDETerminate channelNumber
        
        channelNumber = Application.DDEInitiate("MBENET", "PLC3")
        sheetNumber = 5
        GoSub WriteData
        Application.DDETerminate channelNumber
        Exit Sub
        
    WriteData:
        Set rangeToPoke = ThisWorkbook.Worksheets(sheetNumber).Range("E3")
        If rangeToPoke.Value <> 65535 Then
            Application.DDEPoke channelNumber, "40001", rangeToPoke
            rangeToPoke.Value = 65535
        End If
        Return
    
    End Sub
    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,015

    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,015

    Re: Debug error 13

    You still didn't say which line actually triggers the error. If it's this one:
    If rangeToPoke.Value <> 65535 Then
    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

    If rangeToPoke.Value <> 65535 Then
    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,015

    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,015

    Re: Debug error 13

    You could add an error handler to the code - for example:
    If IsError(rangeToPoke.Value) Then rangetopoke.ClearContents
    If rangeToPoke.Value <> 65535 Then
            Application.DDEPoke channelNumber, "40001", rangeToPoke
            rangeToPoke.Value = 65535

  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,015

    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
    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.

  18. #18
    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

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

    Re: Debug error 13

    If, as you said, this line is causing a type mismatch error:
    If rangeToPoke.Value <> 65535 Then
    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:
    MsgBox rangeToPoke.Value & ": " & rangeToPoke.Text

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

    Re: Debug error 13

    So did you add the error check I suggested?

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

    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