Hi All,
I'm having some issues with this VBA code, I think I'm missing something, but I can;t work out what.
could someone help me at all please?
The code needs to ask if the person is leaving the company or transferring, then follow a slightly different path for each answer.
Thanks
Z
I'm having some issues with this VBA code, I think I'm missing something, but I can;t work out what.
could someone help me at all please?
The code needs to ask if the person is leaving the company or transferring, then follow a slightly different path for each answer.
Thanks
Z
Code:
[COLOR=#000000][FONT=Helvetica Neue]Sub Leavers()[/FONT][/COLOR][COLOR=#000000][FONT=Helvetica Neue]Dim MSG1 As String[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Dim SrchTerm As String, SrchRng As Range, FindThis As Range[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Set SrchRng = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Confirm is leaver or transfer[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]MSG1 = MsgBox("Is advisor leaving the business?", vbYesNo, "Click 'No' if advisor is transferring to another department or moving to centre")[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'LEAVER[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]If MSG1 = vbYes Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]SrchTerm = InputBox("Enter Employee ID", "Process Leaver")[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]If Len(SrchTerm) = 0 Then Exit Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Set FindThis = SrchRng.Find(SrchTerm, lookat:=xlContents)[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Handle invalid Employee ID[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]If FindThis Is Nothing Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] MsgBox SrchTerm & " was not found. Please enter a valid Employee ID", vbInformation, "Error!"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Exit Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Move advisor to Leavers[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Else[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] With FindThis.EntireRow[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] .Copy Sheets("Leavers").Cells(Rows.Count, "A").End(xlUp)(2)[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] .Delete[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Confirm leave date[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] EnterDate = Format(InputBox("Enter Leave Date (mm/dd/yy)", "DATE"), "mm/dd/yy")[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] If IsDate(EnterDate) Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] Sheets("Leavers").Cells(Rows.Count, "U").End(xlUp)(2) = EnterDate[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] Else[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Handle invalid date[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] MsgBox ("Date not entered, please enter manually"), , "DATE ERROR:"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] End With[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'TRANSFER[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]If MSG1 = vbNo Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]SrchTerm = InputBox("Enter Employee ID", "Process Leaver")[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]If Len(SrchTerm) = 0 Then Exit Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Set FindThis = SrchRng.Find(SrchTerm, lookat:=xlContents)[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Handle invalid Employee ID[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]If FindThis Is Nothing Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] MsgBox SrchTerm & " was not found. Please enter a valid Employee ID", vbInformation, "Error!"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Exit Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Move advisor to Leavers[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]Else[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] With FindThis.EntireRow[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] .Copy Sheets("Leavers").Cells(Rows.Count, "A").End(xlUp)(2)[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] .Delete[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Confirm leave date[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] EnterText = InputBox(Prompt:="Enter Move/Transfer Data)", Title:="Advisor Transferring Data")[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] Sheets("Leavers").Cells(Rows.Count, "U").End(xlUp)(2) = EnterText[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] End With[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Open Leavers Template Macro[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] Application.Run "'WFH Master List.xls'!LeaversTemplate"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]'Confirm leaver processed[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] MsgBox "Leaver processed", vbInformation, "Complete"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica Neue]End Sub[/FONT][/COLOR]