Normally, when you double-click a cell, you enter in-cell editing mode, right? This works most of the time, but occasionally on random cells, a double-click instead moves the focus to a different cell in the sheet, as if I had simply single-clicked that other cell. If I then double-click the original cell again, it works as expected: I can edit the contents of that cell and everything is normal. This happens on random cells, regardless what their contents are, and of course they're not hyperlinked or anything like that. It happens on several versions of Excel (XP, 2000, 2003, for certain; can't remember earlier versions). It happens on any computer (at home, at work, at previous workplace.).
![Double Double](/uploads/1/2/5/3/125382049/220720083.gif)
This is not a major problem I need to have solved, but why in the world is Excel behaving like that?! I'd just like to understand it.
![For For](/uploads/1/2/5/3/125382049/441143881.png)
You can also use the 'Before Double Click' event since using the 'Selection Change' event while navigating the worksheet with the arrow keys will also cause the 'X' to be displayed. As Ziggy has already indicated, this code needs to be attached to the workbook object and NOT a stand alone module.
To add the code to the workbook object, open the Excel workbook and in the top left corner of the workbook (next to the file menu) is the Excel Icon. Right click this icon and choose 'View Code.' Then just select the Workbook object and the appropriate event which you would like your code attached from the two drop down comboboxes at the top. Unless you a very picky either event should work just fine. My code works for me, strange it won't work for you.
First, the keyboard shortcut for editing a cell is F2 on Windows, and Control + U. On a Mac, go to preferences by using Command + comma, then click 'Edit'. For the rest of this video, I'll leave that setting, since the shortcuts we're going. To move through text one character at a time, use only the right and left arrow keys. Edit: A single left click on a cell followed by typing will overwrite the cell's contents. F2 will allow you to edit in the cell. Alternatively, double left click followed by typing will insert what you typed at the cursor location when you did the double click.
Did you ensure that you copied the Const as well? @ddockstader: Thanks for taking another look at my code. I did not leave anything out. What you are referring to is found in the ThisWorkbook module, where the sheet is needed to be passed as a variable as it can work for every sheet in the workbook.
This is beneficial if you want to run this code on more than one workbook or if you already have a before double click code in a specific worksheet that you want undisturbed. The difference between my code and ddockstader's code is mine goes into the worksheet module (right click the sheet tab and select View Code) and ddockstader's goes into the workbook module (right click the workbook icon directly left of the File menu and select View Code). To use the code in your ThisWorkbook module (workbook level), ddockstader's code would need two minor adjustments. Code: Option Explicit Const MYRANGE As String = 'A1:A10' Private Sub WorkbookSheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) If Sh.Name 'Sheet1' Then Exit Sub If Target.Cells.Count 1 Then Exit Sub If Intersect(Target, Sh.Range(MYRANGE)) Is Nothing Then Exit Sub Cancel = True If Target.Value = ' Then Target.Value = 'X' Else Target.Value = ' End If End SubThis is because it would need the sheets object to be referenced, otherwise it would run on any activesheet, which may not necessarily be desired. Note the difference is the references of the Sh object.