+ Reply to Thread
Results 1 to 26 of 26

Clicking on row in listbox populates another listbox with relevant data

  1. #1
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Clicking on row in listbox populates another listbox with relevant data

    I have a userform for a music collection that is named "frmRecordings". It has two listboxes on it. Listbox1 ("lstRecordings") populates with all recordings that are on my spreadsheet. When one of those recordings is selected I want listbox2 ("lstTracks") to show the tracks that are on that specific recording. The Tracks are on a separate Sheet in my workbook. And the Tracks sheet has all tracks for all recordings in my collection with a column labled "RecordingID" that can be used to pull up the tracks for that specific recording (I just don't know how). I imagine this is a simple program, but I'm too new to VBA to know how to do it, and I can't find a sample anywhere on the web.
    Here is my code so far for the frmRecording (minus commandbuttons, etc):
    Please Login or Register  to view this content.
    I have also attached the excel workbook.
    Can anyone show me how to filter the tracks for one recording and send that info to lstTracks?

    Here are the columns of my Tracks sheet: ID | TRACK No | TITLE | COMPOSER | COMPOSER2 | COMPOSER3 | PLAY TIME | RECORDINGID
    Each track has it's own ID, and the RECORDINGID is the ID assigned to each recording .
    Let me know what additional info you need.
    Thanks.
    Last edited by AliGW; 06-07-2025 at 09:21 AM. Reason: Code tags added - please review the forum guidelines.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: Clicking on row in listbox populates another listbox with relevant data

    Please, attach a small sample in the form of an excel file.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    Just to give you an idea of what it might look like.
    Attached Files Attached Files
    Last edited by bakerman2; 06-07-2025 at 06:22 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    I'm not sure exactly what kind of a sample you need, but here's a snippet from the Excel file attached.
    I also attached a screen shot of the form.
    Attached Files Attached Files

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,879

    Re: Clicking on row in listbox populates another listbox with relevant data

    Administrative Note:

    Welcome to the forum.

    Is your forum profile up-to-date and showing ONLY the oldest Excel PRODUCT that you need this to work for? Not Windows, please.

    Members will tailor the solutions they offer to the Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your product is for Mac, please also state this.

    The four most recent Excel products are Excel 2019, Excel 2021, Excel 2024 and MS365 - if you are using MS365, please give this name along with the version number in your profile (e.g. MS365 Version 2306). This is in the About Excel section further down the Account page.

    Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  6. #6
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    Your code does exactly what I am looking for. I put the code into my vba and I get the following error: Run-time error '9': Subscript out of range. There must be something in my code that is interfering with your code.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,879

    Re: Clicking on row in listbox populates another listbox with relevant data

    Did you see post #5? Please update your forum profile as requested. Thanks.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,879

    Re: Clicking on row in listbox populates another listbox with relevant data

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.
    For new members: you will not be able to post a full URL, so remove the https://www. section and add one or two breaks to the rest of the address. A Moderator or Admin will then fix the link for you.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are new here, I shall do it for you this time: https://www.mrexcel.com/board/thread...stbox.1273107/)

  9. #9
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    I'm sorry for my slow action to your post. I looked all over for a way to update my profile to show my version of Office, it is MS Office Professional Plus 2013.
    I did post on another site and didn't realize it needed reporting. Is it taken care of now by you? Thank you for your patience.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,879

    Re: Clicking on row in listbox populates another listbox with relevant data

    How to update your forum profile:
    Attached Images Attached Images

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    Attach the workbook with the userform in it.

  12. #12
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    All done. Thanks for the help. Is there any reason I can't find the icon to make an attachment?

  13. #13
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    See attachment
    Attached Files Attached Files
    Last edited by P.alexander; 06-07-2025 at 11:33 AM. Reason: need to send an attachment

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    Here you go.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    bakerman2,
    That is FANTASTIC. Thank you so much. Now, if I'm not seeming ungrateful, a few more issues have stopped working on my form.

    1. The SAVE and DELETE buttons on both the lstRecordings and the lstTracks list boxes are not updating the listboxes when clicked on. They are adding or deleting from the spreadsheet but are only updating the listboxes after I close and reopen the forms.

    2. Is there a way to automatically put the next Track Number into the frmNewTracks form. I tried this before, but since the Track Number column has many duplicates it didn't work right.

    3. I seem to have lost my column heads in both list boxes. I added .columnHeads=True to the code, but it only shows a blank header row.

    Thanks again, Palexander

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    Have to go out for a while but will look at it later today.

  17. #17
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    Took a bit longer then expected ut here it is. Think I covered it all so test and let me know.
    Also fixed the automatic Track number. This will show up after you filled in the RecordingID in the Add Track userform.
    In the Track listbox you can't have Columnheads because this is a filtered range. You can simulate these by putting Labels above the Listbox and line them out with the columns in the ListBox.
    Attached Files Attached Files
    Last edited by bakerman2; 06-08-2025 at 09:52 AM. Reason: Added Labels

  18. #18
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    bakerman2, Once again a GREAT job. there are just a couple more issues.
    1. When adding a new record or a new track, the ID is no longer being automatically generated.
    2. When I highlight and delete a specific track, it actually deletes the track above the selected one.
    I tried fixing this on my own, but to no avail.
    Thank you again for all your work.
    PA

  19. #19
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    bakerman2, I fixed the auto ID on both forms, but when I enter a New Track on the frmNewTrack form only the first one I enter creates a new Track No. After I hit SAVE on the frmNewTrack I am left with entering the next Track no manually.
    The delete button on the frmTrack form still deletes the track above the one selected.
    Last edited by P.alexander; 06-08-2025 at 03:27 PM. Reason: added wording

  20. #20
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    bakerman2, I miss spoke, Delete on the frmTracks works fine. It's the Delete on the lstTracks list box on the frmRecordings that deletes the item above the selection.

  21. #21
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    In my file I've disabled the Auto ID and replaced it with a formula in Column1 on both sheets.
    Doing it that way it doesn't mess up consecutive counting when you delete a row.
    Also I've tested the file I posted extensively on deleting rows on both Recording and Tracks sheet and didn't encounter any errors. The correct row is always deleted.

  22. #22
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    Okay, I see what I was missing. I am use to the ID textbox being filled when the forms were opened, but now I see they don't get filled at all but the ID is added to the sheet upon saving.
    My only question is, why doesn't the .ColumnHeads=True work on the lstTracks listbox? I see it works on the lstRecordings listbox.
    I won't bother you anymore. I wish I had the knowledge of VBA that you do.
    Thank you so much. P.alexander

  23. #23
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    lstRecordings gets filled using RowSource witch refers to a range on a worksheet.
    lstTracks is filled by filtering a range in memory. Therefore ColumnHeads doesn't work and I replaced it with the Labels above the ListBox

  24. #24
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    Thanks for the explanation. I noticed you added text boxes. Does the same thing.
    Now get to bed, it must be after midnight there.

  25. #25
    Registered User
    Join Date
    06-06-2025
    Location
    Tulsa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    23

    Re: Clicking on row in listbox populates another listbox with relevant data

    But before you get to sleep. What about my issue that after I enter a track on the frmNewTracks form and save, I have to manually enter a new Track No. unless I close the form and reopen it.

  26. #26
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,531

    Re: Clicking on row in listbox populates another listbox with relevant data

    In frmNewTracks replace current code with this.
    Please Login or Register  to view this content.

+ 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] effecting change data in listbox based on delete item from another listbox
    By Omran Y in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 07-15-2024, 01:48 AM
  2. Replies: 1
    Last Post: 04-12-2022, 04:38 PM
  3. [SOLVED] Userform combobox populates ListBox errors on clearing control
    By terriertrip in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2017, 04:42 PM
  4. Replies: 1
    Last Post: 05-30-2015, 12:15 PM
  5. [SOLVED] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  6. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM
  7. Userform option button starts a loop that searches worksheet and populates listbox
    By silvertyphoon1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-15-2010, 01:58 AM

Tags for this Thread

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