New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Double-Click to Highlight a Cell

Free Excel Macros

Double-Click to Highlight a Cell

Postby Sisyphus » Fri Feb 10, 2012 4:49 am

This little gadget lets you double-click on any cell in the worksheet to highlight it. Double-click again to remove the highlight. A great reading and editing tool!
Code: Select all
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
                                        Cancel As Boolean)

    ' check VBA help under "PatternColorIndex Property"
    ' for a list of ColorIndex numbers you can use
    ' instead of this one:
    Const MarkColor As Integer = 36

    With Target.Cells.Interior
        If .ColorIndex = MarkColor Then
            .ColorIndex = xlNone
        Else
            .ColorIndex = MarkColor
            .Pattern = xlSolid
        End If
    End With
    Cancel = True       ' this line may be removed
    ' Excel's normal double-click action is to
    ' open the target cell for editing.
    ' This line cancels that action.
End Sub

Install this code on any worksheet's code sheet. The functionality will be available within that sheet only, never the entire workbook.
For modification, observe the remarks at the top and bottom of the code.
Have a great day! :D

Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)
Sisyphus
Former Moderator
 
Posts: 4454
Joined: Dec 7, 2011
Location: Shanghai
Reputation: 203
Excel Version: 2010

Return to Excel Macros

Who is online

Users browsing this forum: No registered users and 9 guests

cron