+ Reply to Thread
Results 1 to 5 of 5

run-time error '13' type mismatch visual basic

Hybrid View

Michell Feitosa run-time error '13' type... 09-22-2012, 11:28 PM
nilem Re: run-time error '13' type... 09-23-2012, 12:38 AM
Michell Feitosa Re: run-time error '13' type... 09-23-2012, 06:28 AM
nilem Re: run-time error '13' type... 09-23-2012, 08:13 AM
Michell Feitosa Re: run-time error '13' type... 09-23-2012, 07:42 PM
  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

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: run-time error '13' type mismatch visual basic

    try it
    MyInput = Application.InputBox(Msg, Title, Type:=1)

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

    Re: run-time error '13' type mismatch visual basic

    It was just brilliant Nilem.

    Thank you so much.

    By the way, Im struggling with the cod to delete the last row of my table, do you have any suggestion. It's going to be in the same macro above.

    Michell

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: run-time error '13' type mismatch visual basic

    hi Michell, try something like this
    Sub AddDeleteRow()
    Dim MyInput As Integer
    MyInput = Application.InputBox(Prompt:="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", _
                                   Default:=1, _
                                   Type:=1)
    If MyInput = 0 Then Exit Sub
    With ActiveSheet.ListObjects(1)
        Select Case MyInput
            Case 1
                MsgBox "Adding row"
                .ListRows.Add
            Case 2
                MsgBox "Deleting last row"
                .ListRows(.ListRows.Count).Delete
        End Select
    End With
    End Sub

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

    Re: run-time error '13' type mismatch visual basic

    yeah its work!!!!

    Thanks a billion Nilem

+ 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