I have an Excel UserForm which contains the following fields; date
, name
and work
.
In the event that the worksheet contains the same date and name pairing, I want data transfer from the Userform blocked.
A worksheet has one entry:
A
has the date 1/1/2017
B
has the name john
For the worksheet above, the following rules apply:
3/1/2017
and john
.1/1/2017
and jane
.1/1/2017
and john
.Dim k As Long
Dim matched As Boolean
matched = False
' Loop over all used rows
For k = 1 to ActiveSheet.UsedRange.Rows.Count
' Check if concatenated string of date & name is unique
' e.g. '01/01/17john'
If ActiveSheet.Cells(k, "A").Text & ActiveSheet.Cells(k, "B").Text = _
myUserForm.DateField.Text & myUserForm.NameField.Text Then
MsgBox "This Name / Date combination is not unique, pick again"
matched = True
Exit For
End If
Next k
If matched = False Then
' Name/Date combination is unique, send data to sub or whatever...
End If