Probklem with code, when merged cells

J

Jan Kronsell

I have the folowwing code, and it works ok in most cases:

Private Sub Worksheet_Change(ByVal Target As Range)
If ((Target.Column = 10) Or (Target.Column = 15)) Then
If Not IsEmpty(Target) Or Target <> "" Then
MsgBox "The cell content has been changed"
End If
End If
End Sub

But if I delete something from a merged cell, in stead of just skipping the
cell (not displaying the messagebox) I get a "Run-Time error '13': Type
mismatch". This only happens on merged cells.

Any idea how to avoid this?

Jan
 
M

Mike H

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Column = 10 Or Target.Column = 15 Then
If Not IsEmpty(Target) Or Target <> "" Then
MsgBox "The cell content has been changed"
End If
End If
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top