简体   繁体   中英

Create a custom shortcut out of a key combination to use in Excel

I need to concatenate a bunch of cells in Excel 365, and would like to create a one button shortcut that would represent Shift and 7 (the & symbol) so it would be just a mouse click and a single key stroke. Is that doable?

Thanks

So for this you need to use VBA, so you need to enable the developer portion and open up the editor. Ok so this portion should go in the ThisWorkbook module in the editor.

Option Explicit
Private Sub Workbook_Activate()
    Application.OnKey "{F7}", "test"
End Sub


Private Sub Workbook_Deactivate()
    Application.OnKey "{F7}"
End Sub

And this portion should just go in any module

Sub test()
ActiveCell.Value = ActiveCell.Value & " & "
End Sub

Once you put it all together either shift to a different workbook or save it, close it and then re-open it and you should be able to hit F7 to insert an &. It's worth noting, however, that it doesn't work if you've clicked into the cell and are editing the formula.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM