Worksheet_SelectionChange allow multiple ranges to be selected

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an input form that pops up when a user selectes a cell, but I want
them to be able to use ctrl to pick non-contiguious cells, but as soon as I
let go of the mouse button, to select the next cell, the form pops up.
I know I've done this before because I have put code in to check the range
of columns selected, which I have tested.

Any Ideas how I stop the form poping up until I have stopped selecting cells?
 
How would excel know you have stopped selecting cells?

Events don't fire when you don't do anything.
 
As the ctrl key needs to be held down to select non-contiguious cells I would
have thought it could detect the ctrl key position
So, taking finger off the ctrl key could be the indicator.
 
I was sure I had done this, but maybe it was only when testing and it failed
leaving Events turned off.
Can I test for ctrl key down in my event?
Then I can control whether to display my form.

Thanks
 
You can test for it, but you just said it would be down.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long)
As Integer

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
'To check wheteher Control key is pressed
If GetAsyncKeyState(17) Then
MsgBox "Control key pressed"
End If
End Sub
 
OK so the event actually fires when I click the mouse in a cell, at which
point ctrl must be down, I had thought the event fired when I let go of the
mouse, so it looks like I'll have to add a toolbar or something.

Thanks for you help
 
Another thought
If I make the form non modal I can select extra cells, but I'm not sure how
to get the info onto my form.
Currently I load the dates (determined by which column the selected cells
are in) into an array, sort it, and then display on my form, to show these
are the dates that will be affected by the form.
How can I re-evaluate which cells are selected?
 
I would guess an update button on the form. When clicked, the code executes
to refresh/revise/update the list.
 
Tom wrote:
<<Events don't fire when you don't do anything.>>

In Excel 2000, the Worksheet_SelectionChange event fires every time you
change anything about the selection.
For example, say cell $A$1 is currently selected. As soon as you press
the shift key and extend the range to include cell $B$2, the
Worksheet_SelectionChange event fires. If you then press the Ctrl key to
add another cell (say cell $D$5), the Worksheet_SelectionChange event
fires again. It fires again when you press the shift key to extend the
2nd area of the selection.
 
Ignore my previous post. I had my newsreader in non-grouped mode
momentarily while checking something else, and didn't see the rest of
the thread.
 

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

Back
Top