Ninja_nutter
New Member
- Joined
- Mar 1, 2016
- Messages
- 21
- Office Version
- 365
- Platform
- Windows
Hello everyone,
At work I have inherited an Excel employee training database. The details of an employee are entered into a user form and can be edited/updated or deleted. The issue I have is that when you go to delete an employee completely, you have to select the employee from the listbox of training courses then delete each line entry. As the criteria is looking for the employees unique employment number, I would like the code to loop through until that unique identifier is completely deleted.
Here is the code:
As i am a newbie to VBA coding any help would be greatly appreciated.
Thanks in advance.
At work I have inherited an Excel employee training database. The details of an employee are entered into a user form and can be edited/updated or deleted. The issue I have is that when you go to delete an employee completely, you have to select the employee from the listbox of training courses then delete each line entry. As the criteria is looking for the employees unique employment number, I would like the code to loop through until that unique identifier is completely deleted.
Here is the code:
Code:
Private Sub cmdDeleteA_Click()
'declare the variables
Dim findvalue As Range
Dim cDelete As VbMsgBoxResult
Dim cNum As Integer
'error statement
On Error GoTo errHandler:
'check for values
If Reg1.Value = "" Or Reg4.Value = "" Then
MsgBox "There is not data to delete"
Exit Sub
End If
'give the user a chance to change their mind
cDelete = MsgBox("Are you sure that you want to delete this person", vbYesNo + vbDefaultButton2, "Are you sure????")
If cDelete = vbYes Then
'find the employee
Set findvalue = Sheet2.Range("F:F").Find(What:=Reg4, LookIn:=xlValues)
findvalue.EntireRow.Delete
End If
'clear the controls
cNum = 9
For X = 1 To cNum
Me.Controls("Reg" & X).Value = ""
Next
'run the filter
AdvFilter
'add the values to the listbox
lstLookup.RowSource = ""
lstLookup.RowSource = "Filter_Staff"
'error block
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _
& Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Please notify the administrator"
End Sub
As i am a newbie to VBA coding any help would be greatly appreciated.
Thanks in advance.
Last edited by a moderator: