+ Reply to Thread
Results 1 to 6 of 6

Runtime Error 13 - Type Mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2017
    Location
    Wellington, New Zealand
    MS-Off Ver
    2010
    Posts
    15

    Exclamation Runtime Error 13 - Type Mismatch

    Hi,

    I am new to VBA and have been mashing together lines of code from different sites to get the result I need. It is rough.

    I think I have got it all working so far except for when I try and delete multiple items from one column (which are dropdown selections). The problem occurs only in this column and nowhere else. Everything is locked down so users can't see or adjust anything outside of what I have left open.

    Code is pasted below. Any help for this would be great!

    When I try delete 2 or more selections in one go from column AE the runtime error 13 appears. The thing this piece of code is achieving is a time stamp for when the status of work changes.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim rInt As Range
        Dim rCell As Range
        Dim tCell As Range
        
    
        Set rInt = Intersect(Target, Range("G4:G2503"))
        If Not rInt Is Nothing Then
            For Each rCell In rInt
                Set tCell = rCell.Offset(0, 37)
                If IsEmpty(tCell) Then
                ActiveSheet.Unprotect Password:="password"
                    tCell = Now
                    tCell.NumberFormat = "mm/dd/yy hh:mm AM/PM"
                ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowFormattingCells:=True
                End If
           
            Next
       
        End If
       
        
        With Target
         
            If .Column <> 31 Or .Row < 3 Then Exit Sub
            If .Value = "In Progress" Then
              ActiveSheet.Unprotect Password:="password"
                If .Offset(0, 14).Value = "" Then
                    .Offset(0, 14).NumberFormat = "mm/dd/yy hh:mm AM/PM"
                    .Offset(0, 14).Locked = True
                    .Offset(0, 14).Value = Now
                End If
                 ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowFormattingCells:=True
            ElseIf .Value = "Complete" Then
              ActiveSheet.Unprotect Password:="password"
                If .Offset(0, 15).Value = "" Then
                    .Offset(0, 15).NumberFormat = "mm/dd/yy hh:mm AM/PM"
                    .Offset(0, 15).Locked = True
                    .Offset(0, 15).Value = Now
                End If
                   ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowFormattingCells:=True
            ElseIf .Value = "Cancelled" Then
              ActiveSheet.Unprotect Password:="password"
                If .Offset(0, 16).Value = "" Then
                    .Offset(0, 16).NumberFormat = "mm/dd/yy hh:mm AM/PM"
                    .Offset(0, 16).Locked = True
                    .Offset(0, 16).Value = Now
                End If
                 ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowFormattingCells:=True
            ElseIf .Value = "On Hold" Then
              ActiveSheet.Unprotect Password:="password"
                If .Offset(0, 17).Value = "" Then
                    .Offset(0, 17).NumberFormat = "mm/dd/yy hh:mm AM/PM"
                    .Offset(0, 17).Locked = True
                    .Offset(0, 17).Value = Now
                End If
                ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowFormattingCells:=True
          End If
          
        End With
    ActiveSheet.Protect Password:="password", AllowFiltering:=True, AllowFormattingCells:=True
    End Sub
    Last edited by AliGW; 01-17-2017 at 02:05 AM. Reason: Code tags added.

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

    Re: Runtime Error 13 - Type Mismatch

    Try putting this on top of code.

    If target.count > 1 then exit 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.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,281

    Re: Runtime Error 13 - Type Mismatch

    Instead of .Value, try .Text.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    01-10-2017
    Location
    Wellington, New Zealand
    MS-Off Ver
    2010
    Posts
    15

    Re: Runtime Error 13 - Type Mismatch

    Great! Text instead of value appears to of solved the problem. Thanks

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Runtime Error 13 - Type Mismatch

    If the cell that's just been changed has an error like #N/A you will get that error.
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,518

    Re: Runtime Error 13 - Type Mismatch

    In future, please use code tags around your code. I have done it for you on this occasion.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. Type Mismatch Runtime Error 13
    By EXCELBENCH in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-21-2015, 05:06 PM
  2. Runtime error 13 - type mismatch
    By Polluz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2014, 11:30 PM
  3. Runtime error'13' - type mismatch
    By Polluz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2014, 01:12 PM
  4. RunTime Error 13: Type MIsmatch
    By tariq2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2013, 10:47 AM
  5. Runtime Error 13 Type Mismatch
    By vtsoldier2010 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2012, 12:59 PM
  6. Runtime error 13: Type mismatch
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2012, 10:06 AM
  7. runtime error 13 type mismatch
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2009, 11:15 PM

Tags for this Thread

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