+ Reply to Thread
Results 1 to 13 of 13

Check if 2 consecutive Form listbox items selected

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Check if 2 consecutive Form listbox items selected

    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

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Check if 2 consecutive Form listbox items selected

    You can count if two items have been selected.
    Please Login or Register  to view this content.
    But to see if they are consecutive, lets see if there are other replies.

  3. #3
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Check if 2 consecutive Form listbox items selected

    please post a sample sheet illustrating what you are trying to do.

  4. #4
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394

    Re: Check if 2 consecutive Form listbox items selected

    If I can plagiarise Davesexcel code and make some minor changes, this will check for consecutive

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Check if 2 consecutive Form listbox items selected

    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.

  6. #6
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Check if 2 consecutive Form listbox items selected

    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

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Check if 2 consecutive Form listbox items selected

    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.

  8. #8
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Check if 2 consecutive Form listbox items selected

    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

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Check if 2 consecutive Form listbox items selected

    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 the icon 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!)

  10. #10
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Check if 2 consecutive Form listbox items selected

    Thanks Jerry

    I appreciate your response.

    I will try your approach in the real world Monday..


    Regards

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Check if 2 consecutive Form listbox items selected

    Checks for consecutive selection and number of selected items.

    Please Login or Register  to view this content.
    If only consecutive selection is allowed you need to check the Selected count is 2.
    Cheers
    Andy
    www.andypope.info

  12. #12
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Check if 2 consecutive Form listbox items selected

    Thanks Andy for your solution. I will test that one out ASAP.

    Jerry - your solution works - thank you again.

    Regards

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Check if 2 consecutive Form listbox items selected

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1