Silverspoon
New Member
- Joined
- Jan 30, 2016
- Messages
- 23
I am trying to set the tab order of a registration form that I created. I am not a coder and do not have any experience in VBA, etc. I'm a newbie at this.
Below is the code that I found on this site that I modified it to reflect my form. However, when I open the form this script does not run. When I open VBA to step through the code I just hear ping sound which indicate something is not working or there is an error but there is no error message.
This script is to set the tab order. I would like it to do the following:
1. First, the top part of the form is to tab the user to enter their name, phone numbers, email ,etc. It should start in cell A3 which is the Salutation (i.e. Mr. Mrs., etc.) field. This section of the form is standard.
2. The IF statement is checking to see if a registration number has been entered into cell B10. If a registration number is provided, Section A of the form cells contents should be cleared and locked. The cursor should then go to Section B cell B26 where the user will enter names.
3. IF a registration number has not been entered, the tab will continue to cell B11.
4. I would also like each field to be in a different color when either pressing the tab button or the enter key. I saw a thread about how to do this but I did not know where in my script should this script be entered. Below is the code that I found from your forum.
Below is my script for tabbing without the code for changing the color.
I appreciate any assistance anyone can provide.
-Thank you in advance
Below is the code that I found on this site that I modified it to reflect my form. However, when I open the form this script does not run. When I open VBA to step through the code I just hear ping sound which indicate something is not working or there is an error but there is no error message.
This script is to set the tab order. I would like it to do the following:
1. First, the top part of the form is to tab the user to enter their name, phone numbers, email ,etc. It should start in cell A3 which is the Salutation (i.e. Mr. Mrs., etc.) field. This section of the form is standard.
2. The IF statement is checking to see if a registration number has been entered into cell B10. If a registration number is provided, Section A of the form cells contents should be cleared and locked. The cursor should then go to Section B cell B26 where the user will enter names.
3. IF a registration number has not been entered, the tab will continue to cell B11.
4. I would also like each field to be in a different color when either pressing the tab button or the enter key. I saw a thread about how to do this but I did not know where in my script should this script be entered. Below is the code that I found from your forum.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Cells.Font.ColorIndex = xlAutomatic
Selection.Cells.Font.Color = RGB(256, 0, 0)
Application.EnableEvents = True
End Sub
Below is my script for tabbing without the code for changing the color.
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim aTabOrd As Variant
Dim iTab As Long
Dim nTab As Long
Dim iNew As Long
aTabOrd = Array("A3", "B3", "D3", "F3", "A4", "B4", "C4", "D4", "A5", "B5", "C5", "B5", "C5", "D4", "B8", "C8", "E8", "B10")
nTab = UBound(aTabOrd) + 1
iTab = 0
If IsEmpty(aTabOrd) Then
If IsEmpty(Range("B10").Value) = True Then 'If regisrtration number entered
'ActiveSheet.Unprotect ("PASSWORD") deactivate until script is working
'ActiveSheet.Protect ("PASSWORD")
'Clear Contents in SECTION A If Hotel Registration NOT Blank. Clear Lock B15:F17 & B19:F20
Worksheets("Hotel Registration Form").Range("B15:F17").ClearContents
Worksheets("Hotel Registration Form").Range("B19:F20").ClearContents
'Lock all Cells in SECTION A
Worksheets("Hotel Registration Form").Range("B15:F17").Locked = False
Worksheets("Hotel Registration Form").Range("B19:F20").Locked = False
MsgBox "You have entered a hotel registration number. Please proceed to SECTIONS B, C, & D to complete the registration form.", vbExclamation, "UK Residents ONLY"
'Set Tab Order to bypass SECTION A
aTabOrd = Array("D10", "E10", "F11", "B26", "B27", "B28", "B30", "B31", "B32", "B33", "C35", "C26", "27", "C28", "C30", "C31", "C32", "C33", "C35", "D26", "D27", "D28", "D30", "D31", "D32", "D33", "C35", "E26", "E27", "E28", "E30", "E31", "E32", "E33", "C35", "F26", "F27", "F28", "F30", "F31", "F32", "F33", "C35", "B38", "C38", "D38", "E38", "B39", "C39", "D39", "E39")
nTab = UBound(aTabOrd) + 1
iTab = 0
End If
'Set Tab Order
aTabOrd = Array("B11", "B15", "B16", "B17", "B19", "B20", "B26", "B27", "B28", "B30", "B31", "B32", "B33", "C35", "C15", "C16", "C17", "C19", "C20", "C26", "C27", "C28", "C30", "C31", "C32", "C33", "C35", "D15", "D16", "D17", "D19", "D20", "D26", "D27", "D28", "D30", "D31", "D32", "D33", "D35", "E15", "E16", "E17", "E19", "E20", "E26", "E27", "E28", "E30", "E31", "E32", "E33", "E35", "F15", "F16", "F17", "F19", "F20", "F26", "F27", "F28", "F30", "F31", "F32", "F33", "F35", "B38", "C38", "D38", "F38", "B39", "C39", "D39", "F39")
nTab = UBound(aTabOrd) + 1
iTab = 0
Else
On Error Resume Next
iNew = WorksheetFunction.Match(Target(1, 1).Address(False, False), aTabOrd, 0) - 1
If Err Then
iTab = (iTab + 1) Mod nTab
Else
iTab = iNew
End If
On Error Goto 0
End If
Application.EnableEvents = False
Range(aTabOrd(iTab)).Select
Application.EnableEvents = True
End Sub
I appreciate any assistance anyone can provide.
-Thank you in advance