Solved

How can I create an IF statement that will find duplicate entries in 10 Text Boxes within a User Form?

Posted on 2012-04-09
3
161 Views
Last Modified: 2012-04-12
My UserForm has 10 TextBoxes into which the user can input an alphanumeric code with the format AB12-34

I would like to introduce an IF statement that runs when the OK button is clicked that compares each of the strings contained within the TextBoxes, and if there is a duplicate it will run some more code.

If the TextBoxes do not contain data then I do not want them to be considered duplicates.

Thanks in advance
Des
0
Comment
Question by:spar-kle
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
gnemi earned 500 total points
ID: 37822695
First thing that's coming to my mind is putting all of the values in an array, sorting the array, then just testing for duplicates in the surrounding values.

So for example

a[0] = 1
a[1] = 3
a[2] = 1

You would sort the array so it would then be a[0] = 1, a[1] = 1, a[2] = 3. Then loop a test that checks if a[0] == a[0+1] or if a[1] == a[1+1].
0
 

Author Comment

by:spar-kle
ID: 37822822
Thanks for your response.
Unfortunately my knowledge is limited and I need you to spell it out to me...
I'm not sure how to compile this in VBA
0
 

Author Closing Comment

by:spar-kle
ID: 37837700
Thanks for the pointer.
Because I didn't know how to "sort the array" I copied the data to a range of cells with code first, and then checked for duplicates there with an IF statement.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now