One more caveat - sorry I missed it earlier. For multiple selections,
the procedure can be quite slow, and could potentially freeze Excel.
To circumvent this issue, find this line:
If Not (Intersect(Target, keyRowRange) Is Nothing) Then
Insert this line directly below it:
Set Target = Intersect(Target, keyRowRange)
Another problem with the code occurs if an entire column is deleted.
In that situation, the adjacent column will be cleared, which is not
desired behavior. So, here's a reworked procedure code, which is more
"elegant" in my estimation, and also avoids the column deletion
issue. I also added comments to clarify exactly what's going on.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim keyRowRange As Excel.Range
Dim rng As Excel.Range
' define row range to be cleared
Const firstRowToClear As Long = 12
Const lastRowToClear As Long = 500
' this ensures that we don't fall into an infinite loop
Application.EnableEvents = False
' define the row address where key values are contained
' replace this with a selection such as B11:J11
' to limit columns affected by this procedure
Set keyRowRange = Me.Range("11:11")
' check to ensure user did not delete the entire column;
' if this is the case, we're done
If Target.Address = Target.EntireColumn.Address Then
GoTo TheEnd
End If
' ensure each column is cleared only once
Set Target = Intersect(Target, keyRowRange)
' if no cells in keyRowRange are being changed, we're done
If (Target Is Nothing) Then GoTo TheEnd
' process each column where the key row has been changed
For Each rng In Target
Me.Range(Me.Cells(firstRowToClear, rng.Column), _
Me.Cells(lastRowToClear, rng.Column)).Clear
Next rng
TheEnd:
' re-enable events to make sure the procedure fires again
Application.EnableEvents = True
End Sub