As you know, Excel allows multiple selections by pressing Ctrl while choosing objects or ranges. This can cause problems with some macros. For example, you can't copy a multiple selection that consists of nonadjacent ranges. (Try it if you don't believe me.)
The following macro demonstrates how to determine whether the user made a multiple selection, so your macro can take appropriate action:
If Selection.Areas.Count > 1 Then
MsgBox "Multiple selections not allowed." Exit Sub End If
This example uses the Areas method, which returns a collection of all objects in the selection. The Count property returns the number of objects in the collection.
Was this article helpful?