+ Reply to Thread
Results 1 to 7 of 7

User of Workbook to Select How Many Times to Run a Macro.

  1. #1
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    User of Workbook to Select How Many Times to Run a Macro.

    I have a macro that copies and pastes a column. User of the workbook may need to run this macro once, or five times, up to at least 20 times in order to copy/paste the column 20 times if needed. I have created a drop down list with the numbers 1 through 20 (1, 2, 3, etc). How can I create a macro that states to run the macro the number of times specified by the user when they choose from the drop down list. Also, can I atached the macro to the number in the drop down list. So if user selects 2 - then the macro is run twice, etc.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: User of Workbook to Select How Many Times to Run a Macro.

    You need two macro's basically. One to detect the number of the dropdown and call the second "copy" macro the requisite number of times.
    The basic format is like this:

    Please Login or Register  to view this content.
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: User of Workbook to Select How Many Times to Run a Macro.

    Thank you for your help. I cannot seem to get this to work. It did not work with the drop down list or even just trying to run straight from the list of macros. Not sure what I have missed doing -- btw, I am running Excel 2010.

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: User of Workbook to Select How Many Times to Run a Macro.

    Have a look at the code in this example
    MultiRunEx.xls

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: User of Workbook to Select How Many Times to Run a Macro.

    A simplified version:

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Registered User
    Join Date
    04-02-2013
    Location
    california, usa
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: User of Workbook to Select How Many Times to Run a Macro.

    I cannot seem to get it to work. So, one dropdown menu and if the user selects 2, then the code runs twice and they get 2 columns, if they select 3 they get 3 columns, etc. Here is the code I use to just do the copy/paste.
    Sub CopyDataToANtoherLocation()
    Dim nEndC1 As Integer
    nEndC1 = Cells (2, Columns.COunt).End(x1ToLeft).Offset(0, 1).Column
    Range("A2:A20").Copy Range(Cells(2, nEndC1), Cells(20, nEndC1))

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: User of Workbook to Select How Many Times to Run a Macro.

    Assuming your dropdown menu is in A1, use this code:

    Please Login or Register  to view this content.
    Change the Range("A1") according to your own data.

    abousetta

+ 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