Checking array to see if value exists before adding to array

W

Wullie

Hi,

I am going round in circles as usual and am doing (at least) one stupid
thing with a lack of logic, so need some help.

I have a list of possible entries that someone can manually enter, which I
then want to check against already entered values of an array and then if
it's not in the array to add it to the next value of the array (up to 4
values).

Can someone please assist me with this or point me in the right direction?

Thanks
 
R

Rick Rothstein

I think we need some more information. Where is this list of possible
entries at... In a declared VB array? In a range of cells? In a String
variable? Somewhere else? Also, what do you mean by "the already entered
value of an array"... is that an array of cells or a declared VB array?
 
W

Wullie

Sorry for the lack of information, I was running out the door as I was typing
it.

Basically, I have a sheet which will holds a number of optional units which
a student can select as part of an overall course.

When a new persons name is added to a column on the sheet 4 mandatory
courses are selected (by putting X in the column beside unit name). The user
is then prompted with an inputbox to enter the code number of the selected
unit. This then loops through the courses to find the selected unit and put
an X in the corresponding box. The input box happens 4 times for 4 optional
units.

This all works OK at the moment, but allows the user to be able to enter the
same course code 4 times, rather than removing the selected one from the
options.

I was trying to get option 1 stored into an array in element 1, then get
option 2 to check if this is the same choice as option 1 and if not, store it
in array element 2, then option 3 to check element 1 and 2 and so on...

At the moment, my code (which I can post tomorrow if required - it's at
work, I'm at home) does all of this but my lack of logic in my code has ment
that where I have my check/add to array, it is adding each option to all of
the array elements.

Just wondering if anyone can help/point me in the direction of a bit of code
that will check the array to see if the value already exists, and if not, add
it to the next element.

Hope this makes a lot more sense, now that I have time to type a bit more in
depth.

Thanks
 
W

Wullie

Thanks for the offer of help Rick.

I changed my code and instead of the user entering values into an input box,
I created a userform with a list of all units and got the user to
select/deselect the required ones, then read the selection out of the list
back into the main code to populate the required boxes with an "X".

Again, thanks anyway
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top