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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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