Option Explicit
Public Function bIsTabOrderValue(ByVal wks As Worksheet) As Boolean
Dim avValueList As Variant
'--edit this list with the names of the sheets to which a custom tab order
' should be applied. Each of these sheets should also have a sequence of
' cell addresses listed in a Case statement in Function GetTabOrder.
avValueList = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
bIsTabOrderValue = _
IsNumeric(Application.Match(wks.Name, avValueList, 0))
End Function
Public Function GetTabOrder() As Variant
' Ver 2 2014 - Dave Timms (aka DMT32) and Jerry Sullivan
'--set the tab order of input cells - change ranges as required
' do not use "$" in the cell addresses.
Dim sNumber As String
sNumber = Sheets("Mutatieformulier").Range("T11").Value
Select Case sNumber
Case "0"
GetTabOrder = Array("I7", "G11")
Case "1"
GetTabOrder = Array("G11", "G13", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", "G24", _
"G27", "G28", "G29", "G33", "G34", "G35", "G36", "G37", "G44", "G45", "G46", "J47", _
"O44", "O45", "O46")
Case "2"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "O13", "O14", "O15", "O16", "O17", "G27", "G28", "G29")
Case "3"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "O13", "O14", "O15", "O16", "O17", "G27", "G28", "G29")
Case "4"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "O18", "O19", "G27", "G28", "G29")
Case "5"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "O23", "G27", "G28", "G29")
Case "6"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "O23", "G27", "G28", "G29", "G33", "G34", "G35", "G36", "G37")
Case "7"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "G27", "G28", "G29")
Case "8"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "G27", "G28", "G29", "O29", "O31", "O32")
Case "9"
GetTabOrder = Array("G11", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", _
"G24", "G27", "G28", "G29", "O28", "O29", "O31", "O32")
Case "10"
GetTabOrder = Array("G11", "G13", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", "G24", _
"G27", "G28", "G29", "G33", "G34", "G35", "G36", "G37", "O13", "O14", "O17", "O29", "O31", _
"O32", "G44", "G45", "G46", "J47", "O44", "O45", "O46")
Case Else
MsgBox "Error: Tab volgorde is niet gespecificeerd voor deze CelWaarde (T11)."
End Select
End Function
Sub SetOnkey(ByVal state As Boolean)
' Ver 2 2014 - Dave Timms (aka DMT32) and Jerry Sullivan
If state Then
With Application
.OnKey "{TAB}", "'TabRange xlNext'"
.OnKey "~", "'TabRange xlNext'"
.OnKey "{RIGHT}", "'TabRange xlNext'"
.OnKey "{LEFT}", "'TabRange xlPrevious'"
.OnKey "{DOWN}", "'UpOrDownArrow xlDown'"
.OnKey "{UP}", "'UpOrDownArrow xlUp'"
End With
Else
'reset keys
With Application
.OnKey "{TAB}"
.OnKey "~"
.OnKey "{RIGHT}"
.OnKey "{LEFT}"
.OnKey "{DOWN}"
.OnKey "{UP}"
End With
End If
End Sub
Sub TabRange(ByVal TabDirection As Integer)
' Ver 2 2014 - Dave Timms (aka DMT32) and Jerry Sullivan
Dim vTabOrder As Variant, m As Variant, i As Long
vTabOrder = GetTabOrder
On Error Resume Next
m = Application.Match(ActiveCell.Address(0, 0), vTabOrder, False)
On Error GoTo ExitSub
'if activecell is not in Taborder array start at first cell
If IsError(m) Then
'goto first cell in array
m = LBound(vTabOrder)
Else
'get corresponding array index
i = m + LBound(vTabOrder) - 1
'increment i value based on tabdirection
i = i + IIf(TabDirection = xlPrevious, -1, 1)
'ensure stay within array bounds
If i > UBound(vTabOrder) Then
i = LBound(vTabOrder)
ElseIf i < LBound(vTabOrder) Then
i = UBound(vTabOrder)
End If
End If
'select cell based on array element
Application.EnableEvents = False
Range(vTabOrder(i)).Select
ExitSub:
Application.EnableEvents = True
End Sub
Sub UpOrDownArrow(Optional iDirection As Integer = xlUp)
Dim vTabOrder As Variant
Dim lRowClosest As Long, lRowTest As Long
Dim i As Long, iSign As Integer
Dim sActiveCol As String
Dim bFound As Boolean
'--get the tab order from shared function
vTabOrder = GetTabOrder
'--find TabCells in same column as ActiveCell in iDirection
'-- rTest will include ActiveCell
sActiveCol = GetColLtr(ActiveCell.Address(0, 0))
iSign = IIf(iDirection = xlDown, -1, 1)
lRowClosest = IIf(iDirection = xlDown, Rows.Count + 1, 0)
For i = LBound(vTabOrder) To UBound(vTabOrder)
If GetColLtr(CStr(vTabOrder(i))) = sActiveCol Then
lRowTest = Range(CStr(vTabOrder(i))).Row
'--find closest cell to ActiveCell in rTest
If iSign * lRowTest > iSign * lRowClosest And _
iSign * lRowTest < iSign * ActiveCell.Row Then
'--at least one cell in iDirection of same columnn
bFound = True
lRowClosest = lRowTest
End If
End If
Next i
If bFound Then
Application.EnableEvents = False
Cells(lRowClosest, ActiveCell.Column).Select
Application.EnableEvents = True
End If
End Sub
Private Function GetColLtr(sAddr As String) As String
Dim iPos As Long, sTest As String
Do While iPos < 3
iPos = iPos + 1
If IsNumeric(Mid(sAddr, iPos, 1)) Then
Exit Do
Else
sTest = sTest & Mid(sAddr, iPos, 1)
End If
Loop
GetColLtr = sTest
End Function