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
160 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

746 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

13 Experts available now in Live!

Get 1:1 Help Now