+ Reply to Thread
Results 1 to 4 of 4

Create a loop to call macro a specified number of times

  1. #1
    Registered User
    Join Date
    07-09-2011
    Location
    ct
    MS-Off Ver
    Excel 2003
    Posts
    2

    Create a loop to call macro a specified number of times

    Hi All,

    I have a copy/paste macro which adds one line to several sheets. I am trying to build code to allow a user to enter a number by input box which will call my copy/paste macro x times until the number of lines matches the number entered by the user. I have used a countif function to determine how many rows in a cell in my worksheet but am not sure how to assign this number to be compared with the number inputed by the user in the input box.

    Your help is greatly appreciated.

    Best,
    Mel

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Create a loop to call macro a specified number of times

    Hello magito,

    Welcome to the Forum!

    If you have a macro written then you should post the code. This will help in developing a workable solution.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Create a loop to call macro a specified number of times

    Hi magito

    Welcome to the Forum. Please post at least the code you have...a sanitized workbook would be better. This'll give us a clearer picture of what you'd like to accomplish.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    07-09-2011
    Location
    ct
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Create a loop to call macro a specified number of times

    Thanks for your responses - The code for my macro is below. Essentially what I am trying to do is to add code to create an input box which will allow a user to enter the number of times the code below will repeat itself. The template has two lines to start with (on 3 worksheets) so the result I am seeking is for the macro to run the number of times entered minus 2 so the number of lines will equal the number entered.

    I am confused on how to compare the input value with the value of the counter in my spreadsheet which is a countif function. I think this can be accomplished with an if then statement which determines if the macro should end or call the sub in the code below to add another row.

    Thanks in advance for your help

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-09-2011 at 09:19 PM. Reason: Corrected Code Tag

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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