PC Review


Reply
Thread Tools Rate Thread

Checking array to see if value exists before adding to array

 
 
Wullie
Guest
Posts: n/a
 
      15th Jun 2009
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
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      15th Jun 2009
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?

--
Rick (MVP - Excel)


"Wullie" <(E-Mail Removed)> wrote in message
news:7381ED87-EC3C-4AE6-8F2F-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Wullie
Guest
Posts: n/a
 
      15th Jun 2009
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


"Rick Rothstein" wrote:

> 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?
>
> --
> Rick (MVP - Excel)
>
>
> "Wullie" <(E-Mail Removed)> wrote in message
> news:7381ED87-EC3C-4AE6-8F2F-(E-Mail Removed)...
> > 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

>
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      19th Jun 2009
Yes, I think it would be helpful if you posted your code.

--
Rick (MVP - Excel)


"Wullie" <(E-Mail Removed)> wrote in message
news:7C997570-E275-402D-9EE6-(E-Mail Removed)...
> 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
>
>
> "Rick Rothstein" wrote:
>
>> 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?
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>> "Wullie" <(E-Mail Removed)> wrote in message
>> news:7381ED87-EC3C-4AE6-8F2F-(E-Mail Removed)...
>> > 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

>>
>>


 
Reply With Quote
 
Wullie
Guest
Posts: n/a
 
      19th Jun 2009
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

"Rick Rothstein" wrote:

> Yes, I think it would be helpful if you posted your code.
>
> --
> Rick (MVP - Excel)
>
>
> "Wullie" <(E-Mail Removed)> wrote in message
> news:7C997570-E275-402D-9EE6-(E-Mail Removed)...
> > 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
> >
> >
> > "Rick Rothstein" wrote:
> >
> >> 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?
> >>
> >> --
> >> Rick (MVP - Excel)
> >>
> >>
> >> "Wullie" <(E-Mail Removed)> wrote in message
> >> news:7381ED87-EC3C-4AE6-8F2F-(E-Mail Removed)...
> >> > 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
> >>
> >>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
example please of how to use Array.Exists method Tim Microsoft VB .NET 2 13th Aug 2007 06:51 PM
Lookup value - see if exists in another array mkondo@deloitte.co.uk Microsoft Excel Worksheet Functions 1 1st Mar 2007 03:55 PM
Adding a NULL to an array then adding array to a data table =?Utf-8?B?RmlkZGVsbTM3NDI=?= Microsoft ADO .NET 4 18th May 2006 07:18 PM
Adding an Array to an Array List Jack Addington Microsoft C# .NET 2 13th Sep 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.