+ Reply to Thread
Results 1 to 5 of 5

Runtime error 13 type mismatch error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Runtime error 13 type mismatch error

    Hi all,

    I'm getting the runtime error 13 type mismatch error on the following line of code.

    The code it relates to is when a cell is changed in H2 (drop down box).

    I get this error when i delete cell values from other cells e.g. when deleting data in range AA30:AA32

    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      If Target = Range("H2") Then      ' If dropdown box in H2 is changed, apply below the below code to each option
    
        If InStr(1, Range("H2"), "Scenario A") > 0 Then      
            Call Unhide_rows
            Call Scenario A
          Else
            If InStr(1, Range("H2"), "Scenario B") > 0 Then
            Call Unhide_rows
            Call Legacy
          Else
                If InStr(1, Range("H2"), "Select") > 0 Then
            Call Unhide_rows
          Else
                    If InStr(1, Range("H2"), "Scenario C") > 0 Then
            Call Unhide_rows
          Else
                        If InStr(1, Range("H2"), "Scenario D") > 0 Then
            Call Unhide_rows
      
      End If
          End If
            End If
                End If
                    End If
                        End If
      
    End Sub
    Last edited by Gti182; 12-06-2016 at 07:56 AM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Runtime error 13 type mismatch error

    If you are deleting multiple cells then you need to specifically check the address of the changed cell(s)

    If Target.Address <> "$H$2" Then Exit Sub
    If only 1 cell was changed, then no problem, but comparing a range of cells to a single cell will error if more than 1 cell was changed.
    Last edited by cytop; 12-06-2016 at 05:32 AM.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,344

    Re: Runtime error 13 type mismatch error

    Does this work for you?

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Address = "$H$2" Then      ' If dropdown box in H2 is changed, apply below the below code to each option
            Select Case Target.Value
                Case "Scenario A"
                    Call Unhide_rows
                    Call Scenario_A
                Case "Scenario B"
                    Call Unhide_rows
                    Call Legacy
                Case "Select", "Scenario C", "Scenario D"
                    Call Unhide_rows
            End Select
        End If
        
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    Re: Runtime error 13 type mismatch error

    Thanks Cytop that's very interesting and useful to know, thanks for the code

    @ Bakerman2 code is nice and tidy and works great thanks!

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,344

    Re: Runtime error 13 type mismatch error

    You're welcome and thanks for adding rep points.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Runtime error'13' - type mismatch
    By Polluz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2014, 01:12 PM
  2. Runtime Error Type Mismatch
    By hungryhobo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-08-2013, 08:50 PM
  3. runtime error 13 type mismatch
    By hughesy8290 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2013, 11:18 AM
  4. Runtime Error 13 -Type mismatch error
    By nikadon in forum Excel General
    Replies: 6
    Last Post: 02-25-2013, 01:37 PM
  5. [SOLVED] runtime error 13 type mismatch
    By chappie in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-30-2012, 10:12 PM
  6. RunTime Error 13 and Type Mismatch...
    By TheNewGuy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-24-2010, 09:24 AM
  7. VB error, runtime error 13 (type mismatch)
    By hindlehey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2005, 08:37 PM

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