VBA Refreshing query throws TYPE MISMATCH in code

Zenru

New Member
Joined
Oct 19, 2017
Messages
29
I have some code which goes about identifying changes in specific columns in a range. Things work fine until I try refresh the query, Excel identifies that as a change and throws a TYPE mismatch error. Thing is, the range I am working on is not part of the query, and when it refreshes it shouldn't do any changes on the ranges I am working.

This is the piece of code giving off problems, the first piece checks if the changes occured in the columns I am checking. The last piece is my attempt at identifying what type of data was the change, if it is numeric an action is triggered, if it is text another is triggered. When I refresh the query I saw that the code runs all the way to the second nested if, there occurs the type mismatch.

What can I do to avoid this?

Code:
If Intersect(Target, tbl.ListColumns("Qty").Range, tbl.DataBodyRange) Is Nothing Then
    If Intersect(Target, tbl.ListColumns("Reason for delay (dip)").Range, tbl.DataBodyRange) Is Nothing Then
        If Intersect(Target, tbl.ListColumns("Reason for delay (Lot)").Range, tbl.DataBodyRange) Is Nothing Then
            If Intersect(Target, tbl.ListColumns("REASON FOR CHANGE").Range, tbl.DataBodyRange) Is Nothing Then Exit Sub
        End If
    End If
End If

Code:
If IsNumeric(Target.Value) Then
    If (Target.Value) < 2 Then
        Application.EnableEvents = False
        Target.Value = ""
        Target.Select
        Application.EnableEvents = True
        Exit Sub
    End If
Else
    If (Target.Value) = "Other" Then
        Set KeyCells = Target.Offset(0, 1)
        ActiveSheet.Unprotect Password:="wowsostrongpw"
        KeyCells.Locked = False
        ActiveSheet.Protect Password:="wowsostrongpw"
        Exit Sub
    Else
        If IsNull(Target.Value) Then
            Exit Sub
        Else
            Exit Sub
        End If
    End If
End If
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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