Hi,
Can someone show me how to test if 2 consecutive list-box items are selected.
Criteria is that only 2 consecutive items must be selected to proceed.
Thanks
Hi,
Can someone show me how to test if 2 consecutive list-box items are selected.
Criteria is that only 2 consecutive items must be selected to proceed.
Thanks
You can count if two items have been selected.
But to see if they are consecutive, lets see if there are other replies.![]()
Please Login or Register to view this content.
please post a sample sheet illustrating what you are trying to do.
If I can plagiarise Davesexcel code and make some minor changes, this will check for consecutive
![]()
Please Login or Register to view this content.
Very nice,
I am using a list of 11 items
If I select the first two items in the list box then click the button I get the the following result.
11000000000
Obviously the 11 = true
If I were to select a third item using your code, I get a result of
11000010000
So I am guessing, we need to count the number of items selected, and if they are =2 then make sure they are consecutive.
Thanks
Dave & MallyCat
@MallyCat - objective is that in a workbook there is x amount of sheets named eg: 26th Mar Wk 12 , 2nd Apr Wk 13 , 9th Apr Wk 14 , 16th Apr Wk15 ...etc
Application workbook 1st lists each of these sheets in a list box and the user must select 2 consecutive sheets that follow each other eg: 2nd Apr Wk 13 & 9th Apr Wk 14
as these sheets are then imported into application workbook, and data from these sheets are used for a specific purpose.
Yes MallyCat, I realise that a sample helps but sometimes a response maybe be given without the need of such.
In this case I would think it was not required..
But then you may say that somebody may have a completely different approach to what I am trying to do, then in that case I would..
Thanks Guys
I am not sure what you just said, was you question answered?
Nowhere in your original post did you mention your listbox contained worksheets.
If somebody asks for a sample workbook, how hard is it for you to provide one?
Everybody here that answers questions does so on a volunteering basis and it is your job that we get all the information required.
Ok Dave didn't mean to upset anyone.
I was thinking a question may produce a answer and then the next step of a sample.
The listbox consecutive selection was the focus not the worksheets
If you request then I shall supply
Regards
Obviously this will need a ton of tweaking for your real-world need, but this approach will subtract the ListIndex of the selected items from each other. The difference should only be 1 if they are listed consecutively, so...
![]()
Please Login or Register to view this content.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
Thanks Jerry
I appreciate your response.
I will try your approach in the real world Monday..
Regards
Checks for consecutive selection and number of selected items.
If only consecutive selection is allowed you need to check the Selected count is 2.![]()
Please Login or Register to view this content.
Thanks Andy for your solution. I will test that one out ASAP.
Jerry - your solution works - thank you again.
Regards
If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.
Last edited by JBeaucaire; 04-24-2012 at 08:14 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks