+ Reply to Thread
Results 1 to 19 of 19

userform Multi select listbox - add contents to list

  1. #1
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    userform Multi select listbox - add contents to list

    hi,

    i have a multi select userform that loads details of a specific month selected, when the userform loads i want to be able to select the rows i need to update and when i press a command button (approved), the word "Yes" is added to the last column (named results). if i click the command button 'reject' i want the word 'no' to be added at the end of that line in results.

    also, i only want the selected month to be shown in the list, at the moment it is showing both months

    workbook attached.
    thanks!
    Attached Files Attached Files
    Last edited by tbar05; 03-20-2013 at 09:07 PM.

  2. #2
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    anyone have any thoughts on this one?

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    If you use RowSource to populate the listbox you won't be able to set Yes/No in the select column.

    Also, you won't be able to filter by month.

    Try this which use AddItem and List to populate the listbox.
    Please Login or Register  to view this content.
    By the way, how many of columns of data are there going to be?

    You've set the column count of the listbox to 13 but there only appears to be 7 (or 8 if counting column A) of data.

    If there is 13 columns then AddItem and List can't be used to populate the listbox, and another method will be needed - probably an array.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    sorry, there is actually 17 columns. i have just made a mock replica of the actual sheet

    I guess i dont necessarily need that many columns since i only need the columns B:F to recognise the data but i still need the results column to show

    also, when i click on Done, how would i get the 'yes' and 'no' to appear in the sheet itself?

    thanks for your help so far, really appreciate it

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    You never mentioned the Done button.

    Where does the data need to go?

    Is it the Result column?

  6. #6
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    yep, in the results column

    sorry for that

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    I''ve updated the code to use an array to store the row numbers that each line of data comes from.

    That array is then used in the Done button code.
    Please Login or Register  to view this content.
    Actually, I've got a question - do you want to deselect the items after you've updated them with Yes/No?

  8. #8
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    yes, ideally they would be deselected after you click approved/reject

  9. #9
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    also, looks like the reject button doesnt put a 'no' next to every selection, only the top one by the looks of it

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    This is the code for deselecting.
    Please Login or Register  to view this content.
    Add that after the line(s) of code that set Yes/No.

  11. #11
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    i added the code like below but it doesnt deselect...

    Please Login or Register  to view this content.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    Sorry, my mistake.

    You need to replace I with idx, which is the loop variable in that code.

    Don't know why I had I, probably force of habit.

  13. #13
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    sorry for the delay, ive been trying to work out the below.

    i put the code in and it seems to be working fine on the mock sheet however i then transferred it to the main workbook im using and i am having trouble getting the correct columns. i changed the code to 16 instead of 6, thinking that should change the columns from H in the sheet i attached to column R in my main sheet

    but i got an error at line:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.


    so basically i need the 'Yes' and 'No' to be in column R instead of H

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    That code isn't putting Yes/No on the worksheet, it puts it in the listbox

    This is the code that does that.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    yeah, i just worked that out

    i changed it to this:

    Please Login or Register  to view this content.
    now i can get it in the right column.

    its just that now, with the original code it puts the 'Yes/No' in the wrong column within the listbox

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    Remind me, what range is the listbox populated with?

    Off the top of my head it starts in column B, and if that's the case then column 16 in the listbox is column R.

    So the code you posted should work.

  17. #17
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    i have changed it to this

    Please Login or Register  to view this content.
    now i have just a blank column at the end of the listbox where i can put the yes/no which is working and is good.

    but id like to have the contents of column R there already in that column (7 in the listbox) so they can see if yes/no has already been entered

    thanks again for your help tho Norie!

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: userform Multi select listbox - add contents to list

    Not quite sure I follow.

    Do you want the existing Yes/No entries to appear in the listbox?

    If you do that should be quite straightforward.

    All we need to do is add code to populate a column in the listbox from column R on the worksheet.

    Perhaps something like this.
    Please Login or Register  to view this content.
    Not sure if I've got the right listbox column so you might need to change that.

    Also, I've used rng.Parent to refer to the worksheet the data is on.

    The only reason I did that was because I couldn't remember the sheet name, you can just change it to Worksheets(<whatever>) if you want.

  19. #19
    Registered User
    Join Date
    07-12-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: userform Multi select listbox - add contents to list

    genius! i think im all done...finally

    thanks Norie, really appreciate it

+ 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