Stop code if cell C8 is selected.

  • Thread starter Thread starter ordnance1
  • Start date Start date
O

ordnance1

I want to add some code to the top of my module that will stop the code if
Cell C8 on the active worksheet is selected.
 
Specifically what do you mean by "stop the code"? If you mean to quit
the currently executing procedure and return to the caller (or to
Excel if there is no caller), use something like


If Not Application.Intersect(Selection, _
Range("C8")) Is Nothing Then
Exit Sub
End If


If you really mean Stop, as in enter debug mode, use an Assert.

Debug.Assert Application.Intersect(Selection, _
Range("C8")) Is Nothing

An Assert enters debug mode if the expression in the Assert is False.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
Back
Top