sanilmathews
Board Regular
- Joined
- Jun 28, 2011
- Messages
- 102
I have created a userform with a TextBox and ComboBox controls. The user key-in Date in TextBox and selects data from each of the ComboBox. Which are then saved to the worksheet named "Dashboard". Below piece of code does that perfectly.
As the entries are made in Dashboard worksheet, I would require a logic that would check for any duplicate entry on a particular date and prevents the user to add the entry to the worksheet. It is perfectly fine for an entry to repeat on a different date.
Not Permitted:
05/08/2018 | Test_1 | Test_2 | Test_3 | Test_4
05/08/2018 | Test_5 | Test_6 | Test_7 | Test_8
05/08/2018 | Test_1 | Test_2 | Test_3 | Test_4
Permitted:
05/08/2018 | Test_1 | Test_2 | Test_3 | Test_4
05/09/2018 | Test_1 | Test_2 | Test_3 | Test_4
Appreciate any help
Thanks!
Code:
Private Sub Add()
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Dashboard")
lRow = ws.Cells(Row.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.txtdate.Value
.Cells(lRow, 2).Value = Me.Combobox1.Value
.Cells(lRow, 3).Value = Me.Combobox2.Value
.Cells(lRow, 4).Value = Me.Combobox3.Value
.Cells(lRow, 5).Value = Me.Combobox4.Value
End With
Me.txtdate.Value
Me.Combobox1.Value = ""
Me.Combobox2.Value = ""
Me.Combobox3.Value = ""
Me.Combobox4.Value = ""
Unload Me
End Sub
As the entries are made in Dashboard worksheet, I would require a logic that would check for any duplicate entry on a particular date and prevents the user to add the entry to the worksheet. It is perfectly fine for an entry to repeat on a different date.
Not Permitted:
05/08/2018 | Test_1 | Test_2 | Test_3 | Test_4
05/08/2018 | Test_5 | Test_6 | Test_7 | Test_8
05/08/2018 | Test_1 | Test_2 | Test_3 | Test_4
Permitted:
05/08/2018 | Test_1 | Test_2 | Test_3 | Test_4
05/09/2018 | Test_1 | Test_2 | Test_3 | Test_4
Appreciate any help
Thanks!