Private Sub TabPressed()
' Deal with Tab, Shift-Tab, and cursor left and right keypresses.
' In the case of Tab and Shift-Tab, the active cell will
' cycle through all cells on a row-by-row basis and will
' loop when the end/beginning of the grid is reached.
' NB This is an extension to Excel default behaviour as
' the normal tab behaviour is to cycle through the cells
' but not to change row. The cursor keys behave as for Excel.
On Error Resume Next
If Not mbCellSelectedByMouse Then
If Not mbShiftPressed Then
If fg.col + 1 <= fg.Cols - 1 Then
fg.col = fg.col + 1
Else
fg.col = 1
If fg.row + 1 <= fg.Rows - 1 Then
fg.row = fg.row + 1
Else
fg.row = 1
End If
End If
Else
If fg.col > 1 Then
fg.col = fg.col - 1
Else
fg.col = fg.Cols - 1
If fg.row > 1 Then
fg.row = fg.row - 1
Else
fg.row = fg.Rows - 1
End If
End If
End If
' The above code does the revelant grid positioning, now make sure
' that the cell to be moved to is an allowed cell
GridAllowedCells
' Check the new column is visible and scroll grid if needed
If Not fg.ColIsVisible(fg.col) Then
fg.LeftCol = fg.col
End If
' Check the new row is visible and scroll grid if needed
If Not fg.RowIsVisible(fg.row) Then
fg.TopRow = fg.row
End If
End If
mbCellSelectedByMouse = False
End Sub