I have a Sheet named Allowances with the following columns:
A: Emp #
B: Employee Name
C: Month
D: Month Code
E: Allowance
F: Allowance Code
G: Overtime Rate
H: Hour
I: Amount
Employee Name and Allowance have Data Validation Combo boxes with Sources as EmpName and Allowance respectively.
EmpName refers to
Allowance refers to
What I need to achieve is prevent duplicate entry for Employee Name (Column B) and Allowance (Colunmn E) Pair. For example:
Employee Name = N1, Allowance=Overtime Payment is OK
Employee Name = N1, Allowance=Leave Encashment is OK
But
Employee Name=N1, Allowance=Overtime Payment is OK
Employee Name=N1, Allowance=Overtime Payment (Not Allowed,Duplicate)
The following code works OK for a single column:
But I need to accomplish this for two columns:
I have the search string for Range.Find method in this:
Excel help provides one code for multiple columns in Range.Find method:
But I am not sure it will work in my scenario as I need to check the actual values in two columns and also, these two columns are not adjacent to each other.
A: Emp #
B: Employee Name
C: Month
D: Month Code
E: Allowance
F: Allowance Code
G: Overtime Rate
H: Hour
I: Amount
Employee Name and Allowance have Data Validation Combo boxes with Sources as EmpName and Allowance respectively.
EmpName refers to
Code:
=OFFSET(LookupValues!$A$2,0,0,COUNTA(LookupValues!$A:$A)-1,1)
Allowance refers to
Code:
=OFFSET(LookupValues!$H$2,0,0,COUNTA(LookupValues!$H:$H)-1,1)
What I need to achieve is prevent duplicate entry for Employee Name (Column B) and Allowance (Colunmn E) Pair. For example:
Employee Name = N1, Allowance=Overtime Payment is OK
Employee Name = N1, Allowance=Leave Encashment is OK
But
Employee Name=N1, Allowance=Overtime Payment is OK
Employee Name=N1, Allowance=Overtime Payment (Not Allowed,Duplicate)
The following code works OK for a single column:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Column
Case 2
MyRange = "$B$2:" & Target.Offset(-1, 0).Address
With Range(MyRange)
If Target.Offset(-1, 0).Address <> "$B$1" And Target.Value <> "" Then
Set c = .Find(Target.Value, LookIn:=xlValues)
If Not c Is Nothing Then
Application.EnableEvents = False
MsgBox "Duplicate values not allowed..."
Target.ClearContents
Application.EnableEvents = True
Exit Sub
End If
End If
End With
End Select
But I need to accomplish this for two columns:
I have the search string for Range.Find method in this:
Code:
target.Offset(0,-3) & target.Value
Excel help provides one code for multiple columns in Range.Find method:
Code:
For Each c In [A1:C5] If c.Font.Name Like "Cour*" Then c.Font.Name = "Times New Roman" End If Next
But I am not sure it will work in my scenario as I need to check the actual values in two columns and also, these two columns are not adjacent to each other.