You can set up a VBA procedure to be executed when the user double-clicks a cell. In the following example (which is stored in the Code window for a Sheet object), double-clicking a cell makes the cell bold (if it's not bold) or not bold (if it is bold):
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Excel.Range, Cancel As Boolean) Target.Font.Bold = Not Target.Font.Bold Cancel = True End Sub
The Worksheet_BeforeDoubleClick procedure has two arguments: Target and Cancel. Target represents the cell (a Range object) that was double-clicked. If Cancel is set to True, the default double-click action doesn't occur.
Notice that I set the Cancel argument to True. Doing this prevents the default action from occurring. In other words, double-clicking the cell won't put Excel into cell edit mode.
Was this article helpful?