PDA

View Full Version : Solved: Escape from Edit Mode



Opv
07-14-2010, 08:46 AM
I have a simple BeforeDoubleClick script to automatically toggle the value of a cell when the user double clicks the cell. The script is working as desired, except that when I double click the cell, I am then in edit mode. I have to press ESC on the keyboard or manually click out of the cell to get out of edit mode.


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


If ActiveCell.Column = 24 And ActiveCell.Row = 2 _
And ActiveCell.Value = "ToSale" Then
ActiveCell.Value = "Select"
Else: ActiveCell.Value = "ToSale"
Call eraseXs
End If

End Sub



Is there a way this script can be modified to force Excel out of edit mode whenever the target cell is doubleclicked?

p45cal
07-14-2010, 09:18 AM
add the line:
Cancel = True

But, as it stands this code will put ToSale in ANY cell that's double-clicked. It only toggles on cell X2. Perhaps you prefer this code which only operates on X2 and preserves edit mode on other cells you double click on but not in X2:Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Column = 24 And ActiveCell.Row = 2 Then
Cancel = True
If ActiveCell.Value = "ToSale" Then
ActiveCell.Value = "Select"
Else
ActiveCell.Value = "ToSale"
Call eraseXs
End If
End If
End Sub

Opv
07-14-2010, 10:15 AM
add the line:
Cancel = True

But, as it stands this code will put ToSale in ANY cell that's double-clicked. It only toggles on cell X2. Perhaps you prefer this code which only operates on X2 and preserves edit mode on other cells you double click on but not in X2:Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Column = 24 And ActiveCell.Row = 2 Then
Cancel = True
If ActiveCell.Value = "ToSale" Then
ActiveCell.Value = "Select"
Else
ActiveCell.Value = "ToSale"
Call eraseXs
End If
End If
End Sub


Thanks for pointing out my oversight, and thanks for the solution.

Opv