ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Preventing Multiple Selections (https://www.excelbanter.com/excel-programming/423142-preventing-multiple-selections.html)

egun

Preventing Multiple Selections
 
Does anyone know how to prevent multiple selections on a worksheet? I just
finished putting together some VBA modules that are working very well, when I
realized that if the user makes multiple selections (using the control key),
then my VBA will break.

I would rather not update the code, and in fact the user should never make
multiple selections with this particular tool. I would rather just prevent
them, if possilble.

Thanks in advance,

Eric


Rick Rothstein

Preventing Multiple Selections
 
I am not aware of a way to prevent multiple selections except through code,
so you will have to modify your existing code or add event code (assuming
you are doing that now with your existing code) to prevent this. Besides, I
doubt whether you would really want to globally restrict multiple
selections. What if the user needed to delete several rows of data for some
reason (or any other scenario involving multiple cells that doesn't deal
directly with your VB code)... would you really want the user to have to
delete each cell's content manually, one cell at a time?

--
Rick (MVP - Excel)


"egun" wrote in message
...
Does anyone know how to prevent multiple selections on a worksheet? I
just
finished putting together some VBA modules that are working very well,
when I
realized that if the user makes multiple selections (using the control
key),
then my VBA will break.

I would rather not update the code, and in fact the user should never make
multiple selections with this particular tool. I would rather just
prevent
them, if possilble.

Thanks in advance,

Eric



Gary''s Student

Preventing Multiple Selections
 
Do you want Selection to be only one cell or only one Area??

If you only want one Area, then:

If Selection.Areas.Count 1 Then
MsgBox "Cannot do this to a multi-area selection."
End If

and then terminate the macro.
--
Gary''s Student - gsnu200829


"egun" wrote:

Does anyone know how to prevent multiple selections on a worksheet? I just
finished putting together some VBA modules that are working very well, when I
realized that if the user makes multiple selections (using the control key),
then my VBA will break.

I would rather not update the code, and in fact the user should never make
multiple selections with this particular tool. I would rather just prevent
them, if possilble.

Thanks in advance,

Eric


Tim Zych

Preventing Multiple Selections
 
Should be easy enough to correct.

Wherever you use Selection , change it to Selection.Areas(1). This will
return the first-selected contiguous range.

--
Tim Zych
http://www.higherdata.com
Compare data in Excel and find differences with Workbook Compare
Free and Pro versions available


"egun" wrote in message
...
Does anyone know how to prevent multiple selections on a worksheet? I
just
finished putting together some VBA modules that are working very well,
when I
realized that if the user makes multiple selections (using the control
key),
then my VBA will break.

I would rather not update the code, and in fact the user should never make
multiple selections with this particular tool. I would rather just
prevent
them, if possilble.

Thanks in advance,

Eric




egun

Preventing Multiple Selections
 
I thank you all for your replies! I know that it's unnatural to restrict
selections like this, but I have my reasons...

Anyway, what I did was go into the Worksheet_SelectionChange event, and if
the new selection has multiple areas, I put up a msgbox and change the
selection back to what it was.

Thanks,

Eric


Harald Staff

Preventing Multiple Selections
 
Hi Eric

The usual approach is to adjust the code, not to alarm the user with
messageboxes.
So your reasons must be of real importance, and they would be of great
interest to us fellow developers. Please share.

Best wishes Harald

"egun" skrev i melding
...
I thank you all for your replies! I know that it's unnatural to restrict
selections like this, but I have my reasons...

Anyway, what I did was go into the Worksheet_SelectionChange event, and if
the new selection has multiple areas, I put up a msgbox and change the
selection back to what it was.

Thanks,

Eric





All times are GMT +1. The time now is 09:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com