PDA

View Full Version : Solved: Disable Double Click



hobbiton73
10-31-2012, 09:47 AM
Hi, I wonder whether someone may be able to help me please.

Firstly my apologies because to some this may be a very stupid error, but I'm only really just starting to learn and understand VBA.

I'm using the code below to attempt to prevent users from double clicking in a cell within a given range.

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("B5:Q2000")) Is Nothing Then Cancel = True
End Sub
Unfortunately it's not working because the 'Double Click' is still enabled and I'm not sure where I'm going wrong.

I just wondered whether someone may be able to take a look at this please and provide some guidance on where my error is?

Many thanks and kind regards

Tommy
10-31-2012, 10:17 AM
Thry this. You are asking the sub to see if the intersect is in this range thenyou inverse it and then compare to nothing.
So the below code means that if the target is in the range I want to cancel the double click.
If Intersect(Target, Range("B5:Q2000")) Then Cancel = True

hobbiton73
10-31-2012, 11:22 AM
Hi @Tommy, thnak you for taking the time to reply to my post and for the proposed solution.

I've made the changes to my code, but unfortunately this doesn't seem to work as the user can still double click in the cells.

I'm not really sure what else I'm doing wrong.

Many thanks and kind regards

Kenneth Hobs
10-31-2012, 12:09 PM
They can still press F2 to edit the cell. Why not protect the sheet and lock the cells if you don't want them to edit the cells?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("B5:Q2000")) Is Nothing Then Cancel = True
End Sub

hobbiton73
11-01-2012, 11:08 AM
Hi @Kenneth Hobs and @Tommy, thank you very much to both of you for taking the time to view and reply to my post.

I have managed to implement both of your suggestions and the spreadsheet works perfectly.

Once again, thank you for your time and kind regards