Results 1 to 5 of 5

run-time error '13' type mismatch visual basic

Threaded View

  1. #1
    Registered User
    Join Date
    09-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2011
    Posts
    18

    run-time error '13' type mismatch visual basic

    Hello,

    I'm a very beginner user of macros, and when a erro comes up, I have no idea how to fix it. Could you guys help me?

    I have a macro to add row or delete rows to the table, and I'm using a message box to do it.
    The problem is, when I select the option "Cancel" the "run-time error '13' " type mismatch, comes up. And when I degub it, the line " MyInput = InputBox(Msg, Title)" is selected in yellow.

    how to fix it?


    Sub AddDeleteRow()
    
    ActiveSheet.Unprotect Password:="secret"
        
        Dim Msg, Title As String
        Dim MyInput As Integer
         ' Define message."
        Msg = "Would you like to Add or Delete last row? " _
        & vbNewLine & "Enter 1 to Add row" & vbNewLine _
        & "Enter 2 to Delete last row"
         
        Title = "Add or Delete last row" ' Define title.
        MyInput = InputBox(Msg, Title)
        Select Case MyInput
        Case 1
            MsgBox "Adding row"
            Range("A4").End(xlDown).ListObject.ListRows.Add AlwaysInsert:=False
        Case 2
            MsgBox "Deleting last row"
        End Select
        
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="secret"
    
    End Sub


    Thanks in advance

    Michell
    Last edited by Leith Ross; 09-23-2012 at 12:16 AM. Reason: Added Code Tags

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