Sub SelectionType()
MsgBox TypeName(Selection)
End Sub
If a Range object is selected, the MsgBox displays Range. If your macro works only with ranges, you can use an If statement to ensure that a range is selected. This example displays a message and exits the procedure if the current selection is not a Range object:
Sub CheckSelection()
If TypeName(Selection) <> “Range” Then
MsgBox “Select a range.”
Exit Sub
End If
‘ … [Other statements go here]
End Sub
