Preventing Multiple Selections

E

egun

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
 
R

Rick Rothstein

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?
 
G

Gary''s Student

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.
 
T

Tim Zych

Should be easy enough to correct.

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

egun

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
 
H

Harald Staff

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top