+ Reply to Thread
Results 1 to 11 of 11

How To Set A ListBox Selection As A Sheet Array

  1. #1
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    How To Set A ListBox Selection As A Sheet Array

    Hi all,

    in the following code, for testing purposes, I have success in writing the data from a userform to all 5 sheets as specified in MyArr...
    Please Login or Register  to view this content.
    What I would like to happen, however, is for the data to be written to one specific worksheet, that worksheet being one of the selections from a listbox (ListBox1 in this case). After trying some variations on ListBox.Selected, Listbox.ListCount, and ListBox.ListIndex, I'm no closer to getting it to work, and again, I think I'm just having problems with the syntax of it all.

    ListBox1 Item 1 = Round 1
    ListBox1 Item 2 = Round 2
    etc

    Anyone got some suggestions for me?

    Cheers,

    AJ
    Last edited by ScotyB; 12-03-2013 at 11:31 PM. Reason: to mark as solved
    Always grateful for the help here - thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How To Set A ListBox Selection As A Sheet Array

    Please Login or Register  to view this content.
    lstbox.value is the text displayed whicch in this case is a worksheet name .. References to worksheet cells now can take the form

    ThisWorkbook.Worksheets(ShtName).Range("A10").value = "XYZ"
    Elegant Simplicity............. Not Always

  3. #3
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    Re: How To Set A ListBox Selection As A Sheet Array

    Thanks for taking a look, Andy, but now I'm even more confused than ever and have no idea as to how to use your example with the code I've currently got written.

    My ListBox1 is populated using the RowSource Property and if I leave the code in red above as it is, it will write the data to all 5 sheets. What I wanted was for the section in red to be something like ...

    Please Login or Register  to view this content.
    so that it would only write to the one sheet that was selected from ListBox1 and this is where I was having trouble with getting the syntax right.

    Does that help?

    Chers,

    AJ

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How To Set A ListBox Selection As A Sheet Array

    Hello ScotyB,

    Can you post a copy of your workbook for review?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    Re: How To Set A ListBox Selection As A Sheet Array

    No worries, Leith,

    sorry if the code is a mish-mash but I'm learning as I go...

    Basically, each of the Userform 'SUbmit Player Data" buttons should write to the next row of the PlayerData sheet (this bit works fine) AND write to the other sheet depending on what is selected in ListBox1 (so, if Round 01 is selected from ListBox1, it should also write to the Round 01 sheet)

    Cheers,

    AJ
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How To Set A ListBox Selection As A Sheet Array

    Hello ScotyB,

    Thanks for posting the workbook. You certainly have done a lot of work on this project. Are you using the option buttons in the ListBox for aesthetics? I only ask since the default setting of a ListBox is single selection.

  7. #7
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    Re: How To Set A ListBox Selection As A Sheet Array

    Leith,

    thanks for the compliment (I still have much to learn, though) and yes, the option buttons are for aesthetics only.

    Cheers,

    AJ

  8. #8
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    Re: How To Set A ListBox Selection As A Sheet Array

    Andy,

    I took another look at the code you offered and experimented a little - I finally understand now how that works. One question; it will display all the worksheet names in the listbox (including hidden ones) and I wondered if there is a way to modify that code so that it excludes any sheet that doesn't have the word 'Round' in it? Some of the sheets are named Round 1, Round 2, etc, and they're the only ones I'd like to appear in the listbox. Is that possible?

    Cheers,

    AJ

  9. #9
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    Re: How To Set A ListBox Selection As A Sheet Array

    Boy, oh boy,

    sometimes the solution is so obvious, it's embarrassing.

    From Andy's snippet of code...
    Please Login or Register  to view this content.
    ... all I had to do was change the order of the worksheets and then change X = 1 to X =7

    So, thanks, Andy, for pointing me in the right direction.

    Leith, I don't know if you're looking at a solution for me but as soon as I test this new bit with the rest of my code, I'll mark this as solved.

    Thanks, guys,

    AJ

  10. #10
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: How To Set A ListBox Selection As A Sheet Array

    Thx Scoty and good effort.

    To avoid displaying the hidden worksheets modify the code to :-

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    08-04-2010
    Location
    Adelaide, Australia
    MS-Off Ver
    Office 365
    Posts
    176

    Re: How To Set A ListBox Selection As A Sheet Array

    Cool, thanks for that, Andy.

    Cheers,

    AJ

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] listbox item selection to got to specific sheet
    By sumonrezadu in forum Excel General
    Replies: 14
    Last Post: 05-17-2013, 12:38 AM
  2. VBA - Can I populate a listbox from an array taken from a listview selection
    By PDIreland in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-22-2012, 06:28 AM
  3. Multi select Listbox Items selection based on other Listbox item selection.
    By srinivassathi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-20-2011, 05:53 AM
  4. Replies: 3
    Last Post: 02-17-2011, 01:40 PM
  5. ListBox Value Selection Placement on Sheet
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-08-2010, 06:02 PM

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