Home » excel » excel – navigate through defined values in cell with arrow key

excel – navigate through defined values in cell with arrow key

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’ve programmed before but I’m new to so please help me.

I want to have a user select a cell (any cell in a column) in a worksheet and then he/she should be able to press the “UP” or “DOWN” arrow keys to navigate through values.

It is similar to a drop down menu.

  1. For example I would have predefined values such “STOP”,”GO”,”START”.
  2. When the user selects the cell and hit the up arrow key once, the value of the cell changes to “GO”, hit the arrow key again, the value changes to “STOP”, and so on ….

thank you any help!

How to&Answers:

Part 1

  1. Right click your sheet tab
  2. View Code
  3. Copy and paste in the code below

This code tells Excel to run your arrow up and down macros only on this sheet. The code is deactivated when you leave the sheet

Private Sub Worksheet_Activate()
    Application.OnKey "{UP}", "UpOne"
    Application.OnKey "{DOWN}", "DownOne"
End Sub

Private Sub Worksheet_Deactivate()
    Application.OnKey "{UP}"
    Application.OnKey "{DOWN}"
End Sub

Part 2

  1. Press ALt & F11 together to go to the Visual Basic Editor
  2. Insert Module
  3. Copy and paste the code below
  4. Press ALt & F11 to go back to excel

      Sub UpOne()
            Select Case ActiveCell.Value
            Case ""
                ActiveCell.Value = "Ready"
            Case "Ready"
                ActiveCell.Value = "Set"
            Case "Set"
                ActiveCell.Value = "Go"
            End Select
        End Sub
    
    
     Sub DownOne()
        Select Case ActiveCell.Value
        Case ""
            ActiveCell.Value = "Go"
        Case "Go"
            ActiveCell.Value = "Set"
        Case "Set"
            ActiveCell.Value = "Ready"
        End Select
    End Sub
    

Your code will now cycle from

blank (if empty) – 1) ready – 2) set – 3) go (for Up Arrow)

blank (if empty) – 1) go – 2) set – 3) ready (for DownArrow)