user2292941
user2292941

Reputation: 89

VBA-Excel Place blinking cursor in selected cell

This is probably super easy, but I can't seem to figure it out.

When I click on any cell on my sheet (single-click), I want the cursor to be in that cell blinking (as if I had double-clicked on the cell)

I am trying to accomplish this using Application.SendKeys "{F2}"

I'm not sure how to actually go about coding something that would identify the selected/activecell in order to use Application.SendKeys "{F2}" ...if that is even possible or the most efficient way to do it.

Or better yet, is there a way to simply call the double-click event to respond to a single-click on a cell?

As always, your input is appreciated!

Upvotes: 1

Views: 3784

Answers (1)

Santosh
Santosh

Reputation: 12353

You may use Worksheet_SelectionChange event. Place below code in any sheet. The below code will highlight the active cell with yellow color on navigation.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Application.EnableEvents = False
    On Error Resume Next

    Cells.Interior.Pattern = xlNone
    ActiveCell.Interior.Color = vbYellow

    Application.EnableEvents = True

End Sub

Alternatively you may consider below

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        Application.EnableEvents = False
    On Error Resume Next


    Cells.Interior.Pattern = xlNone
    ActiveCell.Interior.Color = vbYellow

    Application.EnableEvents = True

End Sub

Upvotes: 2

Related Questions