Test for Multiple Sheets in SELECTION

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,030
My question: I have been unable to locate any property of the SELECTION (or a RANGE) object that will allow me to test to see if the Selection/Range contains cells from multiple worksheets. Does anyone have any ideas?

Why I'm asking...

I have a number of utility-type macros that I have shared with others. I'm trying to make them more error resistant. For example I've already put in a line at the top of most to test that the user doesn't have a chart or shape selected:

If TypeName(Selection) <> "Range" Then BadSelectionMessage "DeleteDuplicateRows", TypeName(Selection)

-- BadSelectionMessage being a generic routine that tells the user of the error of his ways and uses and "END" statement to halt macro execution.

Thanks for any help anyone can offer.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi Greg,

I assume you are referring to the possibility that the user has multiple sheets selected, and therefore the selection is a 3-D range. If so, you can test for this by first checking:

Activewindow.SelectedSheets.Count

If this is greater than 1, the selected range is definitely a 3-D range.
 
Upvote 0

Forum statistics

Threads
1,223,963
Messages
6,175,656
Members
452,664
Latest member
alpserbetli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top