Option Explicit
Dim FlexSource As Range
Dim NumberCheck As Variant
Dim StaffNumberRow As Long
'Variables relating to Personal Info
Dim StaffNumber As Long
Dim FirstName As String
Dim Surname As String
Dim Grade As Integer
Dim DOB As Date
Dim FullOrPartTime As String
'Variables relating to Flex choices
Dim PrivateMedical As String
Sub Lookup_Click()
Set FlexSource = Worksheets("Data").Range("A8:IV60000")
StaffNumber = StaffNumberTB.Value
On Error GoTo ErrorHandler
NumberCheck = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 1, False)
'Lookup employee personal details (for identification) and put on to form
FirstName = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 4, False)
Surname = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 5, False)
NameTB.Text = Surname & ", " & FirstName
Grade = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 13, False)
GradeTB.Text = Grade
DOB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 14, False)
DOBTB.Text = DOB
'Lookup employee Flex choices and put on to form
'Private Medical
If Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 50, False) <> "" Then
PrivateMedical = "No Cover"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 51, False) <> "" Then
PrivateMedical = "Network Self Only"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 52, False) <> "" Then
PrivateMedical = "Network Self & Partner"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 53, False) <> "" Then
PrivateMedical = "Network Self & Children"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 54, False) <> "" Then
PrivateMedical = "Network Family"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 55, False) <> "" Then
PrivateMedical = "Premier Self Only"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 56, False) <> "" Then
PrivateMedical = "Premier Self & Partner"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 57, False) <> "" Then
PrivateMedical = "Premier Self & Children"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 58, False) <> "" Then
PrivateMedical = "Premier Family"
Else: PrivateMedical = "Not Returned Flex"
End If
PrivateMedicalTB = PrivateMedical
'Holiday
'Check to see if Employee is full or part time, then look for holiday choices.
If Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 16, False) = 37.5 Then
FullOrPartTime = "Days"
Else: FullOrPartTime = "Hours"
End If
'Look for Holiday choices
If Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 38, False) <> "" Then
HolidayTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 38, False) & " " & FullOrPartTime & " Reduced Holiday"
ElseIf Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 39, False) <> "" Then
HolidayTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 39, False) & " " & FullOrPartTime & " Additional Holiday"
Else: HolidayTB = "None"
End If
'Vouchers
MandSTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 41, False)
SainsburyTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 42, False)
AsdaTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 43, False)
BootsTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 44, False)
JohnLewisTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 45, False)
GAPTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 46, False)
WhitbreadTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 47, False)
HMVTB = Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 48, False)
'Childcare
ChildcareTB = "£" & Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 40, False)
'Computer
If Application.WorksheetFunction.VLookup(StaffNumber, FlexSource, 48, False) = "y" Then
ComputerTB = "Interested"
Else: ComputerTB = "Not interested"
End If
Exit Sub
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 1004 ' the correct error?
MsgBox "That staff number does not exist on the Flex database"
Case Else
MsgBox "some other error"
End Select
Err.Clear
exit sub
End Sub