I have written a simple macro that gives the user a message when he selects a cell that shouldn't be changed.
It works fine when the user selects a single cell that passes the IF tests and does nothing when the user selects a single cell that doesn't pass the IF tests.
An error occurs when the user selects a multi-cell range. The error message is "Run-time error 13. Type mismatch." Choosing the Debug option takes me to the IF statement.
The tests on target.column and target.count both fail so the problem must be with target.value. Debug mode shows values for target.column and target.count but nothing for target.value. Maybe target.value is undefined for a multi-cell range. How do I deal with this?
Code:
Private Sub Worksheet_Selectionchange(ByVal target As Range)
If target.Column = 19 And target.Count = 1 And target.Value = "EP DLS" Then
MsgBox ("Do not change EP DLS to EP or Mat'l DLS.")
End If
End Sub
It works fine when the user selects a single cell that passes the IF tests and does nothing when the user selects a single cell that doesn't pass the IF tests.
An error occurs when the user selects a multi-cell range. The error message is "Run-time error 13. Type mismatch." Choosing the Debug option takes me to the IF statement.
The tests on target.column and target.count both fail so the problem must be with target.value. Debug mode shows values for target.column and target.count but nothing for target.value. Maybe target.value is undefined for a multi-cell range. How do I deal with this?