Hi there:
I'm seeing some similar requests and code, and I've been trying to accomplish what I need with either one. However, I'm not quite there or get errors.
My apologies that my code below is a skeleton and not organized very well. I was trying a couple of options, and I've not added any error handling or the usual 'with application' blocks yet.
I'm hoping to use the selected cell value from SourceSht and evaluate for dupes from the table from DID_Employee sheet. When it does find dupes, the user will see a message using the information below alerting them that there are dupes and to select the correct EEID. There may be a better solution for that as well.
I appreciate any assistance!
Rob R
I'm seeing some similar requests and code, and I've been trying to accomplish what I need with either one. However, I'm not quite there or get errors.
My apologies that my code below is a skeleton and not organized very well. I was trying a couple of options, and I've not added any error handling or the usual 'with application' blocks yet.
I'm hoping to use the selected cell value from SourceSht and evaluate for dupes from the table from DID_Employee sheet. When it does find dupes, the user will see a message using the information below alerting them that there are dupes and to select the correct EEID. There may be a better solution for that as well.
I appreciate any assistance!
Rob R
VBA Code:
Private Sub TestForDuplicates()
'Determine if duplicate values exist in a provided range and alert user to select the correct EEID
Dim rng1 As Range, frng As Range
Dim myArray As Variant
Dim x As Integer
Dim SourceSht As Worksheet, ws2 As Worksheet
Dim lR1 As Integer, lR2 As Integer
Set SourceSht = ThisWorkbook.Worksheets("Exceptions_HRCases") 'Sheet with source value
Set ws2 = ThisWorkbook.Worksheets("DID_Employee") 'Sheet to find dupes
'Set ws2 = ActiveSheet
With SourceSht
.Range("E2").End(xlDown).Select
End With
With ws2
lR2 = .Cells(.Rows.Count, 2).End(xlUp).Row
End With
Set rng1 = SourceSht.Selection
'Use UNIQUE Function and store result to an Array variable
myArray = WorksheetFunction.Unique(rng1)
'Test Range for Duplicates with COUNTIFS Function *** THIS DOES NOT WORK but I would like to use something similar using the array from ws2. ***
For x = LBound(myArray) To UBound(myArray)
If WorksheetFunction.countifs(rng1, myArray(x,1))> 1 Then
MsgBox "Found more than one value of " & Chr(34) & myArray(1, x) & Chr(34) & " in the cell range. Please confirm EEID."
Exit Sub
End If
Next x
End Sub