Run-time error '13': Type mismatch

alno00

New Member
Joined
Mar 15, 2018
Messages
3
Hello everybody!
I got some amazing help last time I posted, so I'll give it another go.
I'm still very new to coding in excel and find myself stuck with a Run-time error yet again.

This is the code I'm working with:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim n As Long

If Not Intersect(Target, Range("G:J")) Is Nothing Then

    If InStr(1, Target, "SLT003", vbTextCompare) Then
        Target.Offset(0, -4) = "reply 1"
            Else
            Target.Offset(0, -4) = ""
    End If
    
    If InStr(1, Target, "SLT004", vbTextCompare) Then
        Target.Offset(0, -4) = "Reply 1"
    End If

End If
End Sub

Basically, when I enter an SLT-value into a cell, I want the cell 4 steps to the left to automatically enter a reply. The reply should also disappear if the SLT-value is removed.

The code generally works as intended but if I delete rows, enter rows or try to drag fill my SLT value into more cells I recieve a "Run-time error '13': Type mismatch" message.

I'm sure there are many things that could be improved with my code. Any takers? :(

Best regards
/Alexander
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try it like this perhaps:

Code:
Dim rng As Range, c As Range

Set rng = Intersect(Target, Range("G:J"))

If Not rng Is Nothing Then
    For Each c In rng
        If InStr(1, c, "SLT003", vbTextCompare) + InStr(1, c, "SLT004", vbTextCompare) Then
            c.Offset(0, -4) = "reply 1"
        Else
            c.Offset(0, -4) = ""
        End If
    Next
End If
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top