+ Reply to Thread
Results 1 to 9 of 9

Loop through listbox selected items

  1. #1
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Loop through listbox selected items

    Hi There,

    I'm trying to print labels on a brother printer using their SDK - I've got a simple table up and running where I select the row(s) that I want to print, click the button and it prints fine. I'd like to move to using a populated listbox where I can select one or multiple rows and have it use the selected data to populate the label but I'm having trouble.

    Fundamentally I'm getting errors when I try to use
    Please Login or Register  to view this content.
    I think I may be more off the mark than that however! I've attached a sample book, any help would be greatly appreciated.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Loop through listbox selected items

    To count selected items in Listbox.
    Please Login or Register  to view this content.
    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.

  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: Loop through listbox selected items

    In Excel VBA listboxes don't have a SelectedItems collection/property, you need to get the selected items yourself.

    Not sure exactly what you are looking for but this code will populate the table that starts in A4 with the selected items from the listbox.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Loop through listbox selected items

    For printing directly from ListBox selections.
    Please Login or Register  to view this content.
    Last edited by bakerman2; 09-18-2018 at 07:40 AM.

  5. #5
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Loop through listbox selected items

    Thanks for the explanation, I'm getting a subscript out of range error when I try to run that - can you let me know where I've gone wrong?

  6. #6
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Loop through listbox selected items

    Bakerman2 - it's giving me a "next without for" error but the for is there, have I messed something up?

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Loop through listbox selected items

    My bad, put a End If just above Next.

  8. #8
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Loop through listbox selected items

    Thanks so much, that's great! It wasn't printing with the first row so I changed r = 1 to r = 0and it seems to be good now.

    Thanks both for your help!

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Loop through listbox selected items

    Glad to help and thanks for rep+.

+ 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. Listbox pre-selected items
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2017, 12:16 AM
  2. [SOLVED] Loop find all matches of listbox items, display results in another listbox
    By banaanas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2015, 02:56 AM
  3. Selected Listbox Items to Sheet
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 04:54 AM
  4. [SOLVED] Add Selected Items From One ListBox to Another ListBox on UserForm
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2014, 06:53 PM
  5. Copy Selected items from multicolumn, multiselect listbox to another listbox
    By Willigb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2013, 11:27 AM
  6. Transfer random listbox items to new listbox and then loop through selected items
    By narrowgate88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2013, 05:58 PM
  7. [SOLVED] How to use selected items from Listbox
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2006, 11:10 AM

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