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("Big E Crane", "Concrete Pump", "Crawler Crane", "Mobile Crane", "Self Erecting", "Spider Crane", "Cropper", "Dumper and Rollers", "Excavator", "Generator", "Hoist", "Mast Climber", "Scissor And Boom", "Forklift")
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("Tab_Order").Range("A1").Value
Select Case sNumber
Case "Big E Crane"
GetTabOrder = Array("J4", "J5", "J7", "J8", "J9", "J10", "S6", "S7", "S9", "S10", "B24", "E31", "K31", "E32", "K32", "Q32", "F37", "J37", "N37", "R37", "F38", "J38", "N38", "R38", "F39", "J39", "N39", "R39", "F40", "J40", "N40", "R40", "F41", "J41", "N41", "R41", "F42", "J42", "N42", "R42", "B46", "I54", "S54", "I55", "S55")
Case "Concrete Pump"
GetTabOrder = Array("J4", "J5", "J7", "J8", "J9", "J10", "S6", "S7", "S9", "S10", "B24", "E31", "K31", "E32", "K32", "Q32", "F37", "J37", "N37", "R37", "F38", "J38", "N38", "R38", "F39", "J39", "N39", "R39", "F40", "J40", "N40", "R40", "F41", "J41", "N41", "R41", "F42", "J42", "N42", "R42", "B46", "I54", "S54", "I55", "S55")
Case "Crawler Crane"
GetTabOrder = Array("J4", "J5", "J7", "J8", "J9", "J10", "S6", "S7", "S9", "S10", "B24", "E31", "K31", "E32", "K32", "Q32", "F37", "J37", "N37", "R37", "F38", "J38", "N38", "R38", "F39", "J39", "N39", "R39", "F40", "J40", "N40", "R40", "F41", "J41", "N41", "R41", "F42", "J42", "N42", "R42", "B46", "I54", "S54", "I55", "S55")
Case "Mobile Crane"
GetTabOrder = Array("J4", "J5", "J7", "J8", "J9", "J10", "S6", "S7", "S9", "S10", "B24", "E31", "K31", "E32", "K32", "Q32", "F37", "J37", "N37", "R37", "F38", "J38", "N38", "R38", "F39", "J39", "N39", "R39", "F40", "J40", "N40", "R40", "F41", "J41", "N41", "R41", "F42", "J42", "N42", "R42", "B46", "I54", "S54", "I55", "S55")
Case "Self Erecting"
GetTabOrder = Array("J4", "J5", "J7", "J8", "J9", "J10", "S6", "S7", "S9", "S10", "B24", "E31", "K31", "E32", "K32", "Q32", "F37", "J37", "N37", "R37", "F38", "J38", "N38", "R38", "F39", "J39", "N39", "R39", "F40", "J40", "N40", "R40", "F41", "J41", "N41", "R41", "F42", "J42", "N42", "R42", "B46", "I54", "S54", "I55", "S55")
Case "Spider Crane"
GetTabOrder = Array("J4", "J5", "J7", "J8", "J9", "J10", "S6", "S7", "S9", "S10", "B24", "E31", "K31", "E32", "K32", "Q32", "F37", "J37", "N37", "R37", "F38", "J38", "N38", "R38", "F39", "J39", "N39", "R39", "F40", "J40", "N40", "R40", "F41", "J41", "N41", "R41", "F42", "J42", "N42", "R42", "B46", "I54", "S54", "I55", "S55")
Case "Cropper"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "R30", "E30", "E31", "E32", "B44", "H50", "R50", "H51", "R51")
Case "Dumper and Rollers"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "Q30", "Q34", "B39", "H45", "R45", "H46", "R46")
Case "Excavator"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "D30", "D31", "D32", "M32", "B42", "H49", "R49", "H50", "R50")
Case "Generator"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "L31", "O31", "L32", "O32", "L33", "O33", "Q38", "Q39", "B45", "H50", "R50", "H51", "R51")
Case "Hoist"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "Q31", "Q32", "Q33", "D34", "D35", "S36", "S37", "R38", "R39", "B43", "H49", "R49", "H50", "R50")
Case "Mast Climber"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "C31", "P31", "C32", "P32", "P33", "R35", "P36", "P37", "P38", "B43", "H48", "R48", "H49", "R49")
Case "Scissor And Boom"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "L30", "Q30", "F31", "H36", "H37", "H38", "S36", "S37", "S38", "B42", "H49", "R49", "H50", "R50")
Case "Forklift"
GetTabOrder = Array("I5", "I6", "I8", "I9", "I10", "I11", "R6", "R7", "R9", "R10", "D17", "E19", "K19", "E20", "K20", "Q20", "R25", "P31", "T31", "P32", "T32", "J32", "J33", "K39", "Q39", "B43", "H49", "R49", "H50", "R50")
Case Else
MsgBox "Error"
End Select
End Function
Public Function Load_Calendar_Userform() As Variant
Dim sNumber As String
sNumber = Sheets("Tab_Order").Range("A1").Value
Select Case sNumber
Case "Big E Crane"
Load_Calendar_Userform = Array("S6", "S55")
Case "Concrete Pump"
Load_Calendar_Userform = Array("S6", "S55")
Case "Crawler Crane"
Load_Calendar_Userform = Array("S6", "S55")
Case "Mobile Crane"
Load_Calendar_Userform = Array("S6", "S55")
Case "Self Erecting"
Load_Calendar_Userform = Array("S6", "S55")
Case "Spider Crane"
Load_Calendar_Userform = Array("S6", "S55")
Case "Cropper"
Load_Calendar_Userform = Array("R6", "R51")
Case "Dumper and Rollers"
Load_Calendar_Userform = Array("R6", "R46")
Case "Excavator"
Load_Calendar_Userform = Array("R6", "R50")
Case "Generator"
Load_Calendar_Userform = Array("R6", "R51")
Case "Hoist"
Load_Calendar_Userform = Array("R6", "R50")
Case "Mast Climber"
Load_Calendar_Userform = Array("R6", "R49")
Case "Scissor And Boom"
Load_Calendar_Userform = Array("R6", "R50")
Case "Forklift"
Load_Calendar_Userform = Array("R6", "R50")
Case Else
MsgBox "Error"
End Select
End Function
Public Function Load_Dimension_Userform() As Variant
Dim sNumber As String
sNumber = Sheets("Tab_Order").Range("A1").Value
Select Case sNumber
Case "Big E Crane"
Load_Dimension_Userform = Array("F39", "J39", "N39", "R39")
Case "Concrete Pump"
Load_Dimension_Userform = Array("F39", "J39", "N39", "R39")
Case "Crawler Crane"
Load_Dimension_Userform = Array("F39", "J39", "N39", "R39")
Case "Mobile Crane"
Load_Dimension_Userform = Array("F39", "J39", "N39", "R39")
Case "Self Erecting"
Load_Dimension_Userform = Array("F39", "J39", "N39", "R39")
Case "Spider Crane"
Load_Dimension_Userform = Array("F39", "J39", "N39", "R39")
Case "Cropper"
Load_Dimension_Userform = Array("")
Case "Dumper and Rollers"
Load_Dimension_Userform = Array("")
Case "Excavator"
Load_Dimension_Userform = Array("")
Case "Generator"
Load_Dimension_Userform = Array("")
Case "Hoist"
Load_Dimension_Userform = Array("")
Case "Mast Climber"
Load_Dimension_Userform = Array("")
Case "Scissor And Boom"
Load_Dimension_Userform = Array("")
Case "Forklift"
Load_Dimension_Userform = Array("")
Case Else
MsgBox "Error"
End Select
End Function
Sub Check_Forms(vTabOrder, i)
Dim vDim_Form As Variant, F As Integer, vCal_Form As Variant
'Ver 1 - Marc Moore Aka 99moorem 04-09-2014
'Used to load on Events but events must be disabled below is the same functionality
'for my two userforms
vDim_Form = Load_Dimension_Userform
For F = 0 To UBound(vDim_Form)
If vDim_Form(F) = vTabOrder(i) Then
OpenDimension Range(vTabOrder(i)), Range(vTabOrder(i)).Value
Exit For
End If
Next
vCal_Form = Load_Calendar_Userform
For F = 0 To UBound(vCal_Form)
If vCal_Form(F) = vTabOrder(i) Then
OpenCalender Range(vTabOrder(i))
Exit For
End If
Next
End Sub
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)
'range locked increment i
If Range(vTabOrder(i)).Locked Then
i = i + IIf(TabDirection = xlPrevious, -1, 1)
End If
' second range locked increment i
If Range(vTabOrder(i)).Locked Then
i = i + IIf(TabDirection = xlPrevious, -1, 1)
End If
'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
Check_Forms vTabOrder, i
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