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
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

626 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