+ Reply to Thread
Results 1 to 7 of 7

Export contents of listbox to new excel workbook

  1. #1
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Question Export contents of listbox to new excel workbook

    I've got a userform that searches a database for certain criteria and displays the results in a list box with 7 columns. I'm now trying to figure out the code to export the contents of that listbox into a new workbook executing with a command button, appreciate any help!
    Last edited by jstn; 09-20-2014 at 02:42 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Export contents of listbox to new excel workbook

    Try something like this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Export contents of listbox to new excel workbook

    Hi

    This is all you need to fill and store entries from a listbox.
    I have included a few redundant lines to give you some hints.

    Please Login or Register  to view this content.
    This code stores the whole listbox. How often will you need to do that?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 09-20-2014 at 12:59 PM.

  4. #4
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Re: Export contents of listbox to new excel workbook

    That does the trick, thank you! seems so simple, I suspected it would be but couldn't nail it down.
    The whole list box contents is what I needed, the filtering is done on the userform.

    A small adjustment if possible, the list box doesn't have headers, but the database it pulls from does, could I have the headers added into the exported file? Could we also size the columns in the workbook to fit the data?

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Export contents of listbox to new excel workbook

    Quote Originally Posted by jstn View Post
    A small adjustment if possible, the list box doesn't have headers, but the database it pulls from does, could I have the headers added into the exported file? Could we also size the columns in the workbook to fit the data?
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-04-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    48

    Re: Export contents of listbox to new excel workbook

    Thank you again, that's perfect! Is there a way to declare the column headers?

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Export contents of listbox to new excel workbook

    You're welcome.

    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. Activate the first workbook from the listbox, copy all the contents & close it
    By kit370 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2014, 07:38 PM
  2. I would need a macro to export data from base example workbook to export worbook
    By slato8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:21 AM
  3. Replies: 1
    Last Post: 07-08-2010, 06:10 AM
  4. Replies: 1
    Last Post: 08-07-2008, 02:11 PM
  5. Export TextBox contents to new workbook.
    By Andy Tallent in forum Excel General
    Replies: 0
    Last Post: 02-22-2005, 10:06 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