Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Can I use the OnAction or OnKey method to move to a specified cell in Excel?

I'm trying to program a key (the Tab key specifically, but I'll take any key) to move to a specified cell when it's clicked.

I've tried this:

Sub Test()

Application.OnKey "{tab}", "Move5"

End Sub

Public Sub Move5()

Cells(Cells.activerow, Cells.activecolumn + 5).Select

End Sub

but it doesn't call the Move5 proc. Any help?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Put this into Thisworkbook module

    Private Sub Workbook_Open()

    Application.OnKey "{tab}", "Move5"

    End Sub

    Put this into a regular module

    Public Sub Move5()

    Cells(ActiveCell.Row, ActiveCell.Column + 5).Select

    End Sub

    Save and close the workbook then re-open it, it will work as expected

  • 1 decade ago

    Try the Excel forums at: http://peach.ease.lsoft.com/

    Sign up is free. There is a large group of Excel experts that can assist you with ANY question on Excel or Excel VBA.

Still have questions? Get your answers by asking now.