willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 929
- Office Version
- 365
- Platform
- Windows
Hello, I am looking for a code that will compare cells A2:A50 from "New Employee" sheet with cells A3:A1000000 in "Employee List" sheet and if a duplicate entry is found it will prompt a message box stating "duplicate entry found", highlight the duplicate and end the macro.
I have a master employee listing on "Employee List" and on "New Employee" is where you can enter new employee information (Column A is the employee number).
You would enter all the employee information and hit an update button to run the macro.
The Macro would then copy the entries, find the last blank cell in the table in "Employee List" and past the information. However I do not want the Macro to run if a duplicate entry is found.
Instead I would like it to flag the problem so the user can fix it and then properly update.
Here is my current code without the find duplicate option:
Sub EUpdate()
'
' EUpdate Macro
'
'
If ThisWorkbook.Sheets("New Employee").Range("A2").Value = "" Then
MsgBox "Employee # has not been entered. Please enter a valid Employee # to Proceed"
Exit Sub
End If
Dim Msg As String, Ans As Variant
Msg = "Would you like to update the Master Employee List with this Data?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
Sheets("Employee List").Select
ActiveWorkbook.SlicerCaches("Slicer_Supervisor").ClearManualFilter
ActiveWorkbook.SlicerCaches("Slicer_Building").ClearManualFilter
ActiveSheet.ListObjects("Table1").AutoFilter.ShowAllData
Sheets("New Employee").Select
Range("A2:K50").Select
Selection.Copy
Sheets("Employee List").Select
Range("Table1").Cells(1, 1).End(xlDown).Offset(1).Select
ActiveSheet.Paste
Range("D3").Select
LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Range("D3:D" & LastRowColumnA).Formula = "=[@[First Name]]&"" ""&[@[Last Name]]"
Range("A1").Select
Sheets("New Employee").Select
Range("A2:K50").Select
Selection.ClearContents
Range("A2").Select
MsgBox "Update Complete"
Case vbNo
GoTo Quit:
End Select
Quit:
End Sub
Your help would be greatly appreciated.
Thank you
Carla
I have a master employee listing on "Employee List" and on "New Employee" is where you can enter new employee information (Column A is the employee number).
You would enter all the employee information and hit an update button to run the macro.
The Macro would then copy the entries, find the last blank cell in the table in "Employee List" and past the information. However I do not want the Macro to run if a duplicate entry is found.
Instead I would like it to flag the problem so the user can fix it and then properly update.
Here is my current code without the find duplicate option:
Sub EUpdate()
'
' EUpdate Macro
'
'
If ThisWorkbook.Sheets("New Employee").Range("A2").Value = "" Then
MsgBox "Employee # has not been entered. Please enter a valid Employee # to Proceed"
Exit Sub
End If
Dim Msg As String, Ans As Variant
Msg = "Would you like to update the Master Employee List with this Data?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
Sheets("Employee List").Select
ActiveWorkbook.SlicerCaches("Slicer_Supervisor").ClearManualFilter
ActiveWorkbook.SlicerCaches("Slicer_Building").ClearManualFilter
ActiveSheet.ListObjects("Table1").AutoFilter.ShowAllData
Sheets("New Employee").Select
Range("A2:K50").Select
Selection.Copy
Sheets("Employee List").Select
Range("Table1").Cells(1, 1).End(xlDown).Offset(1).Select
ActiveSheet.Paste
Range("D3").Select
LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Range("D3:D" & LastRowColumnA).Formula = "=[@[First Name]]&"" ""&[@[Last Name]]"
Range("A1").Select
Sheets("New Employee").Select
Range("A2:K50").Select
Selection.ClearContents
Range("A2").Select
MsgBox "Update Complete"
Case vbNo
GoTo Quit:
End Select
Quit:
End Sub
Your help would be greatly appreciated.
Thank you
Carla