I am using 10 textboxes on a userform and then have an 'OK' button to enter the data. I am looking for a need way of saying 'If any of the txtbox values are equal or if they are empty then exit sub.
Any help appreciated.
Are these the only textbox controls on the userform? What are the names of the controls? Are they the standard TextBox1, TextBox2, etc.?
Iterate through the Controls property and checks a prefix of names or put the controls into a control Array and iterate through it if you didn't use a common prefix.
You can put the values into an array and use one of various methods to remove duplicates. A search for the work Unique and Array may find a routine easy enough. If the Ubound(arrayname) of each is the same then no duplicates were removed. Collections and a Dictionary object are other methods that would work.
See if this gets you started.
Dim c As Control
Dim a() As Control
Dim i As Long
For Each c In UserForm1.Controls
i = i + 1
ReDim Preserve a(i)
Set a(i) = c
Debug.Print "a(" & i; ")", a(i).Name
Here is something that I have used to fill a control with unique values from a range. You can use a similar concept.
Sub FillCtrlUnique(myRange As Range, myControl As Control)
Dim Coll As New Collection
Dim var As Variant
Dim cell As Range
On Error Resume Next
For Each cell In myRange
Coll.Add Item:=cell.Value, key:=CStr(cell.Value)
On Error GoTo 0
For Each var In Coll
Set Coll = Nothing