[VBA] Condition to check if (merged) cell is in error

Snypa

New Member
Joined
Nov 1, 2013
Messages
45
Hello,

I have the following code:

Code:
If Not Intersect(Target, Range("C8:D8")) Is Nothing And Range("C8").Value <> "" And Not IsError(Range("C8").Value) Then
The code runs when the cell is selected but I do not want it to run if the cell shows an error.
I tested this when the cell showed #NAME error and the VBA throw a type mismatch exception. Please could anyone offer a a better solution?
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
38,559
Office Version
365
Platform
Windows
Try
Code:
If Intersect(Target, Range("C8:D8")) Is Nothing Then Exit Sub
If IsError(Range("C8").Value) Then Exit Sub
If Range("C8").Value <> "" Then
   'do something
End If
 

Watch MrExcel Video

Forum statistics

Threads
1,095,382
Messages
5,444,129
Members
405,269
Latest member
Kjtakke

This Week's Hot Topics

Top