Originally Posted by
bobkap
I I am guessing that the "target" range includes the whole worksheet by default.
Target is the range of cells that were changed (assuming we are talking about a Change event), so you can test if that range has any cells you might be interested in. Normally, you are probably expecting the user to change one cell at a time, so you could do this (where I have made up a range of interest, C3:F10, because you didn't tell us what it actually is)...
Code:
If Intersect(Target, Range("C3:F10")) Is Nothing Then Exit Sub
However, it is possible for a user to paste in values where some or all of the values intersect the area of interest. How to handle this kind of depends on what any remaining code in the Change event, or what your macro does with the cells that were change. If the code in either location needs to work with the cells that actually changed, then a loop might be appropriate...
Code:
Dim Cell As Range
If Intersect(Target, Range("C3:F10")) Is Nothing Then Exit Sub
' Since we got here, one or more cells in Target intersected with C3:F10, so...
For Each Cell In Intersect(Target, Range("C3:F10"))
' The Cell variable is a reference to a cell that changed, so your code can do whatever is need to or with it
Next
Bookmarks