I have made an excel form and it works of a fashion but I want to insert a line into worksheet Driver Training Log alphabetically by column B then colum C. Row 1 is the column titles. Any guidance will be appreciated My code is;
#
Private Sub Cmdbutton_add_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Driver Training Log")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(Me.textbox_lastname.Value) = "" Then
Me.textbox_lastname.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 2).Value = Me.textbox_terminal.Value
ws.Cells(iRow, 3).Value = Me.textbox_lastname.Value
ws.Cells(iRow, 5).Value = Me.textbox_firstname.Value
ws.Cells(iRow, 6).Value = Me.textbox_contractstatus.Value
ws.Cells(iRow, 7).Value = Me.textbox_group.Value
ws.Cells(iRow, 8).Value = Me.textbox_licenceexp.Value
ws.Cells(iRow, 9).Value = Me.textbox_adrexp.Value
ws.Cells(iRow, 10).Value = Me.textbox_aapractical.Value
ws.Cells(iRow, 11).Value = Me.textbox_aatheory.Value
ws.Cells(iRow, 12).Value = Me.textbox_drivercoachaa.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.textbox_terminal.Value = ""
Me.textbox_lastname.Value = ""
Me.textbox_firstname.Value = ""
Me.textbox_contractstatus.Value = ""
Me.textbox_group.Value = ""
Me.textbox_licenceexp.Value = ""
Me.textbox_adrexp.Value = ""
Me.textbox_aatheory.Value = ""
Me.textbox_aapractical.Value = ""
Me.textbox_drivercoachaa.Value = ""
Me.textbox_lastname.SetFocus
End Sub
Private Sub Cmdbutton_close_Click()
Unload Me
End Sub
Private Sub textbox_aapractical_Change()
End Sub
Private Sub textbox_aatheory_Change()
End Sub
Private Sub textbox_terminal_Change()
End Sub
Private Sub UserForm_Click()
End Sub
#
Bookmarks