Sendkey F2 for range of cells

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have been looking for a straightforward and reliable method to do sendkey "F2" on range of cells.

I want users to be sent directly to edit mode when selecting certain cells, which will allow them to copy or enter data in a more user friendly manner.

Kind regards,
Luke
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You need VBA for that. It's also recommended to use the advantage of Excel's feature to name a range of certain cells.
If you agree then select all the required cells while pressing the CTRL key and name them "CertainCells" (without the quotes) using the name box, which is usually visible to the left of the formula bar.
After that, right click on the tab of the worksheet to be affected to open its context menu, click View Code to open the VBE within the worksheets code module and paste the code below in the right hand pane. See if this works for you.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge = 1 Then
        If Not Excel.Application.Intersect(Target, Range("CertainCells")) Is Nothing Then
            VBA.SendKeys "{F2}"
        End If
    End If
End Sub
 
Upvote 0
Solution
You need VBA for that. It's also recommended to use the advantage of Excel's feature to name a range of certain cells.
If you agree then select all the required cells while pressing the CTRL key and name them "CertainCells" (without the quotes) using the name box, which is usually visible to the left of the formula bar.
After that, right click on the tab of the worksheet to be affected to open its context menu, click View Code to open the VBE within the worksheets code module and paste the code below in the right hand pane. See if this works for you.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge = 1 Then
        If Not Excel.Application.Intersect(Target, Range("CertainCells")) Is Nothing Then
            VBA.SendKeys "{F2}"
        End If
    End If
End Sub
Amazing! Worked Perfectly. I was even able to edit VBA code to work with protected sheets and merged cells.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge > 1 Then


        If Not Excel.Application.Intersect(Target, Range("CertainCells")) Is Nothing Then
        ActiveSheet.Unprotect Password:=""
            VBA.SendKeys "{F2}"
              Else

    ActiveSheet.Protect Password:=""
        End If
    End If
End Sub
 
Upvote 0
P.S For all questions i've asked on this forum and others. This was perhaps the most clear, concise and helpful response i've ever received. If you ever do any consulting work please feel free to let me know, as your ability to understand problems and communicate is excellent.
 
Upvote 0
You're welcome and thanks for the feedback (y)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top