I’m using Excel VBA and have a worksheet_change event like so:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("rel_type") Then
--some code
End If
End Sub
That code works great when I make a change to the named range “rel_type”. However if I insert a row anywhere else in the spreadsheet, I get run-time error 13 – type mismatch on the first line of that Sub. Does anybody know a workaround? I’m not that familiar with the Worksheet_Change event and can’t seem to find good documentation (or at least documentation that references why this error would occur). Thanks.
Is this what you are trying?
FOLLOWUP
INTERSECT: The Intersect Method will return a Range Object that represents the intersection of two, or more, ranges.
See this link
Topic: Intersect Method [Excel 2003 VBA Language Reference]
Link: Intersect – MSDN
ENABLEEVENTS: You have to use the EnableEvents property to prevent any probable endless loops which the VBA code might initiate. When you set this property to
False, VBA will not raise any events and theWorksheet_Changeevent will run only once. Also you should always be sure to set EnableEvents property back toTrueto enable events to be called normally the next time.HTH
Sid