Try this:
-mortCode:Option Explicit Const conLEFT = 0 Const conRIGHT = 1 Const conUP = 2 Const conDOWN = 3 Sub NextCell(iDirection As Integer) 'Call this sub to move active cell 1 space. 'iDirection: 0-Left, 1-Right, 2-Up, 3-Down. On Error GoTo ehOffSheet With ActiveWindow.ActiveCell Select Case iDirection Case conLEFT ActiveSheet.Cells(.Row, .Column - 1).Activate Case conRIGHT ActiveSheet.Cells(.Row, .Column + 1).Activate Case conUP ActiveSheet.Cells(.Row - 1, .Column).Activate Case conDOWN ActiveSheet.Cells(.Row + 1, .Column).Activate End Select End With exNextCell: Exit Sub ehOffSheet: MsgBox "Attempt to move off sheet!", vbExclamation Resume exNextCell End Sub




Reply With Quote