+ Reply to Thread
Results 1 to 10 of 10

userform listbox

  1. #1
    Registered User
    Join Date
    03-16-2012
    Location
    florida
    MS-Off Ver
    mac 2008
    Posts
    63

    userform listbox

    i cannot figure out how to copy a name from listbox 2 to a cell (B1), press print, copy the next name to B1, print, next name etc, until all the names in that listbox are printed at which point it stops. any ideas on how to get this code to work? thanks a million in advance everyone.
    Last edited by tsiguy96; 02-15-2013 at 03:18 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    How have you populated the listbox?
    Upload a file and ill figure out where you are at.


  3. #3
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    Hi.

    I m not sure but this is what I understood from your explaination. The print part I m not clear. Check if this is what you needed:

    copylistboxdataandprint.xlsm
    Click *, if my suggestion helps you. Have a good day!!

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    The reason i asked about the way that you where populating the list, if you where using an array or other methods this may be an *** about way of doing things.

    Try the other responce, Cheers for cutting my grass. Ill just go back behind my rock. Kidding.

    Please Login or Register  to view this content.
    This is a simple loop., The way it works is using a variable to store the number of items that have been populated in the list,this number is retirved be using listbox.listcount. Though rember that the placement of the listbox stars at 0 and not 1. Thats why the varaible is -1 and the loop starts at 0.
    Then its just a matter of changing the cell.value and using the printout function to print the sheet.
    Last edited by D_Rennie; 02-14-2013 at 03:21 AM. Reason: optional

  5. #5
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    .............

  6. #6
    Registered User
    Join Date
    03-16-2012
    Location
    florida
    MS-Off Ver
    mac 2008
    Posts
    63

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    This works perfect, the only thing I need it to do now is print to the appropriate sheet. How do i amke it print to Sheet 2, Cell b1? Thanks, you are awesome i spent hours searching this!

    edit:

    so with this code:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    it only prints out the LAST name on my listbox2. if i have 5 names on there, it will print out the last name 5 times instead of doing every name. why is that?
    Last edited by tsiguy96; 02-14-2013 at 10:48 AM.

  7. #7
    Registered User
    Join Date
    03-16-2012
    Location
    florida
    MS-Off Ver
    mac 2008
    Posts
    63

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    does anyone see why taht code would ONLY print out the last name on the list, yet it would do it the number of times as their are names in the list? thanks, dont know how you guys learn this stuff but its genius.

  8. #8
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    a oversight in the loop change to .Sheets(2).Range("A1").Value = ListBox2.List(X)
    the variable x is the changing number allowing the loop to change +1 each time and lstqty is in your case a constant of 4

    i see you have changed the code to print sheet 2 though if you want to only print a selected cell, try recording a macro manually and see what it outputs, from there you will see a line that will say something like .printrange or allong those lines and use use this in the above code

  9. #9
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    a oversight in the loop change to .Sheets(2).Range("A1").Value = ListBox2.List(X)
    the variable x is the changing number allowing the loop to change +1 each time and lstqty is in your case a constant of 4

    i see you have changed the code to print sheet 2 though if you want to only print a selected cell, try recording a macro manually and see what it outputs, from there you will see a line that will say something like .printrange or allong those lines and use use this in the above code\
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-16-2012
    Location
    florida
    MS-Off Ver
    mac 2008
    Posts
    63

    Re: userform listbox - copy listbox 2 to cell, then print, multiple times

    rennie, your new code along with the print code from the old one works perfect. i cant thank you enough for helping me figure this out!

+ 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