+ Reply to Thread
Results 1 to 8 of 8

need a userform to multiselect sheets and run loop macro

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    need a userform to multiselect sheets and run loop macro

    I have tried creating a userform that able to show a list of worksheetnames in the listbox.
    Please Login or Register  to view this content.

    However I have no idea how I can run a macro for each of the sheets that have been selected in my listbox one by one.

    I don't want the macro to run all at once, instead i need it to loop sheet by sheet.

    I have tried many ways, and failed miserably.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: need a userform to multiselect sheets and run loop macro

    Hi boon-yao.tek,

    Firstly you need to change the MultiSelect property of your form from fmMultiSelectSingle to fmMultiSelectMulti so the user(s) can select more then option from the ListBox1 listbox. Then use this code:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: need a userform to multiselect sheets and run loop macro

    I tried your code, still doesn't work.

    I have attached a sample file here.

    Can you help to have a look?

    basically my macro codes is to append all the sheets table into one tab called "sales". I want a userform to select which sheets I need to combine basically because in the real file, there is many more sheets and some I don't need to combine.

    sample.xlsm

    i know the append function can be easily achieve with using Microsoft Access but my current company disallow us to use that. =(

  4. #4
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: need a userform to multiselect sheets and run loop macro

    okay

    i have added this line

    Please Login or Register  to view this content.

    now it works for a single sheet.
    when i select a few sheets, the debug error prompts out stating run-time error '9', subscript out of range and it highlighted 'Sheets.(intSelectionIndex).Select' .

  5. #5
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: need a userform to multiselect sheets and run loop macro

    Thanks alot Trebor76

    I figured it out.

    Somehow this is how I needs to modify the file.

    First of all, I need to use fmMultiSelectMulti and not fmMultiSelectExtended for the listbox

    Secondly, I need to tweak my code to look like this. Not sure why though.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: need a userform to multiselect sheets and run loop macro

    when i select a few sheets, the debug error prompts out stating run-time error '9', subscript out of range and it highlighted 'Sheets.(intSelectionIndex).Select'
    The there is no tab in the workbook with the exact same name that is being selected from the listbox.

    First of all, I need to use fmMultiSelectMulti and not fmMultiSelectExtended for the listbox
    That's what I said to do in my first post

    Secondly, I need to tweak my code to look like this. Not sure why though.
    The actual two lines of code (the rest are comments) are what I also provided in my first post

    Robert

  7. #7
    Registered User
    Join Date
    09-10-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: need a userform to multiselect sheets and run loop macro

    Thanks Trebor76.

    Here is my finalized sample file.
    Combine Success1.xlsm
    Hope others might find it useful.

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: need a userform to multiselect sheets and run loop macro

    Thanks Trebor76.
    You're welcome and thanks for marking the thread as solved and for adding to my reputation

    Regards,

    Robert

+ 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] For next loop multiselect activex listbox won't list items in seperate cells. Only 1st
    By Dabbler39 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-05-2013, 03:25 PM
  2. [SOLVED] MultiSelect Listbox in Userform to copy data to worksheet
    By aarodn in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-06-2013, 03:52 PM
  3. [SOLVED] listindex=0 when first item selected in a multiselect listbox on a userform?
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-17-2013, 12:38 PM
  4. Unable to Detect When UserForm MultiSelect ListBox Selection Changes
    By ShortSword in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2012, 10:49 PM
  5. userform multiselect listbox problem
    By apndas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2006, 11:12 PM

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