Get the type name
Public Sub TestActiveControl() If TypeName(ActiveSheet) <> "Worksheet" _ Or TypeName(Selection) <> "Range" Then MsgBox "You can only run this macro in a range", vbCritical Exit Sub End If End Sub