Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rngF As Range, rngC As Range
Dim aCell As Range, bCell As Range
Dim wkSheet1 As Worksheet
'recursive error prevention
On Error GoTo Whoa
Application.EnableEvents = False
If Target.Cells.CountLarge > 1 Then GoTo Letscontinue
'___set range
Set wkSheet1 = ThisWorkbook.Worksheets("backend")
Set rngF = wkSheet1.Range("C5:C500,H5:H500,M5:M500,R5:R500,W5:W500,AB5:AB500" & _
",AG5:AG500,AL5:AL500,AQ5:AQ500,AV5:AV500,BA5:BA500,BF5:BF500," & _
"BK5:BK500,BP5:BP500,BU5:BU500,BZ5:BZ500,CE5:CE500,CO5:CO500," & _
"CT5:CT500,CY5:CY500,DD5:DD500,DI5:DI500,DN5:DN500," & _
"DS5:DS500,DX5:DX500,EC5:EC500")
Set rngC = wkSheet1.Range("D5:D500,I5:I500,N5:N500,S5:S500,X5:X500,AC5:AC500," & _
"AH5:AH500,AM5:AM500,AR5:AR500,AW5:AW500,BB5:BB500,BG5:BG500," & _
"BL5:BL500,BQ5:BQ500,BV5:BV500,CA5:CA500,CF5:CF500,CP5:CP500," & _
"CU5:CU500,CZ5:CZ500,DE5:DE500,DJ5:DJ500,DO5:DO500," & _
"DT5:DT500,DY5:DY500,ED5:ED500")
'fORECAST
If Not Application.Intersect(Target, rngF) Is Nothing Then
'~~> Loop through all cells in the range
For Each aCell In rngF
If aCell.Value <> "" Then
If aCell.Value <> "N/A,TBC,TBA,TBD" Then
If aCell.Value < Date Then
aCell.ClearContents
MsgBox "The Forecast date you have specified " & _
"may not occur in the past. Please try again"
Else
End If
End If
End If
Next
End If
'complete
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Target, rngC) Is Nothing Then
'~~> Loop through all cells in the range
For Each bCell In rngC
If bCell.Value <> "" Then
If bCell.Value > Date Then
bCell.ClearContents
MsgBox "The Forecast date you have specified " & _
"may not occur in the past. Please try again"
Else
End If
End If
Next
End If
Letscontinue:
Application.EnableEvents = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume Letscontinue
End Sub
The question: I used If Target.Cells.Count > 1 Then Exit Sub
to try get the sub to exit as soon as more than 1 cell had been affected. IE: After a single target cell in any of the specific ranges is affected, stop executing the clear cell contents on any others. Im sure my syntax is wrong or the logic needs a tweak. I've omitted part of the code that isn't affected.