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?
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