When i click a button on my worksheet the below event is called.
I get the error ‘Type mismatch’
I suspect I need another if statement to stop the original IF being evaluated if the event is due to a button being pressed?
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("D4") Then 'Error is here
End If
End Sub
This
is equivalent to this
which clearly is not what you want. You will probably get the error you describe if
Target.Valuehappens not to be of the same type asRange("D4").Value.What you want is this:
EDIT I just managed to reproduce your error. It occurs if the
Targetrange is of a different size thanRange("D4")i.e. spans more than one cell. As @Dick Kusleiska notes, it also occurs if one of the two is an error value. Maybe it’s triggered by other things as well, I don’t know. Anyhow, the point is, yourIfcondition is wrong!