Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
167 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

926 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