When running a macro to work with a range is triggered while a chart on the worksheet is active, your macro will fail.
Use the following code to check for a range selection to prevent this error from occurring.

You can use VBA's TypeName function to check the Selection.

Here's an example:

<pre>If TypeName(Selection) <> "Range" Then
MsgBox "Please select a range of cells!"
Exit Sub