Function GetDate(ByVal Text As String) As Variant
If IsDate(Text) Then GetDate = DateValue(DateAdd("yyyy", 1, Text)) Else GetDate = Text
End Function
Private Sub CommandButton1_Click()
Dim TargetRow As Long, LastRow
Dim FullName As String 'full name
Dim wsData As Worksheet
Set wsData = ThisWorkbook.Worksheets("Data")
FullName = Txt_FirstName & " " & Txt_LastName
LastRow = wsData.Cells(wsData.Rows.Count, "E").End(xlUp).Row
With ThisWorkbook.Worksheets("Engine")
.Visible = True
With .Range("B3")
If .Offset(, 1).Value = "NEW" Then
If Application.WorksheetFunction.CountIf(wsData.Range("E8:E" & LastRow), FullName) > 0 Then
MsgBox FullName & Chr(10) & "Name already exists", 64, "Check"
Exit Sub
End If
TargetRow = .Value + 1
Else
TargetRow = .Value
End If
End With
End With
Application.ScreenUpdating = False
'Begin Data Input to Database
'Begin Data Input to Database
With wsData.Range("Data_Start")
.Offset(TargetRow, 0).Value = TargetRow
.Offset(TargetRow, 1).Value = Txt_FirstName 'first name
.Offset(TargetRow, 2).Value = Txt_LastName 'last name
.Offset(TargetRow, 3).Value = Txt_FirstName & " " & Txt_LastName 'full name
.Offset(TargetRow, 4).Value = Txt_Phone 'contact number
.Offset(TargetRow, 5).Value = Combo_Craft 'craft
.Offset(TargetRow, 6).Value = Combo_Classification 'classification
.Offset(TargetRow, 7).Value = Combo_Group 'group affiliation
.Offset(TargetRow, 8).Value = Txt_BadgeNumber 'BP badge number
.Offset(TargetRow, 9).Value = Txt_AKIDNumber 'L&I ID number
'increment dates + 1 year
.Offset(TargetRow, 10).Value = GetDate(Txt_DrivingCert) 'BP driving cert
.Offset(TargetRow, 11).Value = GetDate(Txt_ATFLCert) 'All terrain forklift cert
.Offset(TargetRow, 12).Value = GetDate(Txt_MLCert) 'manlift cert
.Offset(TargetRow, 13).Value = GetDate(Txt_RespCert) 'respirator cert
.Offset(TargetRow, 14).Value = GetDate(Txt_CSECert) 'confined space entry cert
.Offset(TargetRow, 15).Value = GetDate(Txt_CSACert) 'confined space attendant cert
.Offset(TargetRow, 16).Value = GetDate(Txt_LOTOCert) 'lockout tagout cert
.Offset(TargetRow, 17).Value = GetDate(Txt_SkidSteerCert) 'bobcat cert
.Offset(TargetRow, 18).Value = GetDate(Txt_FELCert) 'front end loader cert
End With
Sheets("Engine").Visible = xlVeryHidden
Unload Me 'close the user form
MsgBox FullName & Chr(10) & " was added to database", 64, "Complete"
Application.ScreenUpdating = True
End Sub