Weird behavior on Worksheet_beforedoubleclick event (XL2003)

K

ker_01

I have some code that handles the doubleclick event on a target sheet
(relevant code pasted at the bottom of this post).

Approximately 30% of the time, when I try to double-click, the selected cell
(target) will randomly move to a different cell before my second click,
thereby not triggering the double-click event. It doesn't move my cursor; the
selected cell (highlighted) will actually suddenly jump to a different cell
leaving my cursor over my intended target cell. Example:

Cell E31 is selected (single click; the cursor is not within the cell so it
is not in edit mode)
I double click on cell D20 (very fast, inter-click delay is not an issue)
-the first click selects cell D20 ( the box around the cell highlights) as
expected
-the second click occurs, without moving the mouse
Some other random cell is selected, and my code does not fire.
While re-testing to write this email, once it jumped to cell D28, another
time it jumped to D11.

I've not had reason to use the double-click event before, and I've never
seen this behavior before- so I'm thinking that just having the double-click
event "enabled" may be causing problems. I can't see anything in my code that
would cause this behavior. I'm open to any ideas, because I'd really like to
get a reliable double-click on a target cell 100% of the time!

Note that I added the msgbox to confirm whether the code is firing- when the
selection jumps, I don't get the msgbox. When I do get the msgbox, the
everything processes as expected (userform and subsequent code all works fine)

Thanks,
Keith


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

Msgbox "x"
If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then
NameVal = Target.Value
If NameVal <> "" And Target.Row > 2 And (Target.Column = 3 Or
Target.Column = 4 Or Target.Column = 5) Then

UserForm1.show

End If
End If
End Sub
 
K

ker_01

That sounds like it is probably the same thing- I'm not finding that the
final cell selection is at the end of a used range (it is all over the
place), and the cell contents don't have formulas, so it isn't referencing a
precedent cell... but I'll try the solution provided in this thread and
hopefully take care of it-

Thank you very much for the link, I didn't find this in my search prior to
posting.

Best,
Keith
 
K

ker_01

Well, it actually didn't work as well as I had hoped. I agree with you that
turning off draganddrop is a bad idea because users may have other workbooks
open, and I'd be interfering with the whole Excel application until my
workbook closed (putting d&d = true in the close event).

So instead I tried Jim's suggestion, and I keep getting a weird macro not
found error. For example:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.CellDragAndDrop = False
'Application.OnTime Now + TimeSerial(0, 0, 0.5), "ResetDragAndDrop"
Application.OnTime Now + TimeSerial(0, 0, 1),
Application.CellDragAndDrop = True
End Sub

At first I was using the separate ResetDragAndDrop procedure, but I was
getting the macro not found error. I thought maybe I could circumvent that by
just keeping everything in one sub, but now I'm getting the error that it
can't find the macro [path\]!False, as if it is looking for a sub called
"False". With continuous pop-ups, I think I'm better off going back the the
problem of random cell selection...

Thanks,
Keith
 

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