+ Reply to Thread
Results 1 to 10 of 10

Repeat Macro Based on Number of Cell Value

  1. #1
    Registered User
    Join Date
    10-07-2016
    Location
    Tucson, AZ
    MS-Off Ver
    Windows 10 Excel 2013
    Posts
    5

    Repeat Macro Based on Number of Cell Value

    I am trying to repeat a macro the number of times it indicates on a cell value.

    I've tried what other websites have posted with no luck.

    Neither of the following 3 codes work for me. What am I doing wrong?

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 10-07-2016 at 07:08 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Repeat Macro Based on Number of Cell Value

    1) Please update your profile to list your Excel versions, not Windows 10.

    2) The first macro would be the way to go. But the loop is empty. What is supposed to be done for each value of i in the loop?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,865

    Re: Repeat Macro Based on Number of Cell Value

    What do you want the macro to do. There does not seem to be any action for the macro to do other than loop.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    10-07-2016
    Location
    Tucson, AZ
    MS-Off Ver
    Windows 10 Excel 2013
    Posts
    5

    Re: Repeat Macro Based on Number of Cell Value

    I would like it to Call WRITETOTEXT.

    The macro is called "WRITETOTEXT"

    The cell value on Sheet4!$A$2 is 3. It is only doing it (looping) once.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Repeat Macro Based on Number of Cell Value

    1) Please edit your profile that it list lists your Excel Version(s), it currently states Windows 10, which is meaningless to, we need to know you Excel version(s).

    2) Just because the call the macro multiple times doesn't automatically mean it won't just do the same thing 3 times, it may look no different than if it had only run once.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 10-13-2016 at 10:59 AM.

  6. #6
    Registered User
    Join Date
    10-07-2016
    Location
    Tucson, AZ
    MS-Off Ver
    Windows 10 Excel 2013
    Posts
    5

    Re: Repeat Macro Based on Number of Cell Value

    I updated my profile. I am using Windows Excel 2013.

  7. #7
    Registered User
    Join Date
    10-07-2016
    Location
    Tucson, AZ
    MS-Off Ver
    Windows 10 Excel 2013
    Posts
    5

    Re: Repeat Macro Based on Number of Cell Value

    For this Macro
    Please Login or Register  to view this content.


    Where would I put "Call Macro1"?
    Last edited by JBeaucaire; 10-13-2016 at 10:56 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  8. #8
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Repeat Macro Based on Number of Cell Value

    Right in between the FOR and the NEXT.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Repeat Macro Based on Number of Cell Value

    1) First you would always remember to put CODE tags around all posted code. My signature demonstrates how up in post #2.

    I've edited your post above. Please try to remember in the future. Thanks.


    2) This is often referred to as a For/Next loop, that indicates the start and end of a loop routine. Anything in between those lines IS the loop.

    Look at post #5, it is demonstrated there using WRITETOTEXT instead of Macro1. Just edit that previous example as needed.

  10. #10
    Registered User
    Join Date
    10-07-2016
    Location
    Tucson, AZ
    MS-Off Ver
    Windows 10 Excel 2013
    Posts
    5

    Re: Repeat Macro Based on Number of Cell Value

    Ok, so Macro2() is supposed to call Macro: WRITETOTEXT
    Macro WRITETOTEXT allows me to save the data in my Excel Spreadsheet onto a Notepad in my drive and then save to a folder in my network.

    Please Login or Register  to view this content.
    The magic is, once the notepad is saved to the folder on the network, it prints.
    Therefore, I was hoping that by running this macro several times, it would print several times.

    If I run WRITETOTEXT, it immediately prints. However the repeat macro Macro2() won't run WRITETOTEXT as many times as the cell value Sheet4!$A$2 indicates.

    I hope this makes sense.

+ 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. Repeat text count based on unique ID number
    By rn_ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2015, 04:04 PM
  2. repeat macro based on a cell value
    By cmedved07 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2014, 03:17 PM
  3. repeat macro based on a cell value
    By cmedved07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-18-2014, 12:09 PM
  4. macro needed to repeat cell values for a specified number of times
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2014, 06:54 AM
  5. Macro or Eqn to Repeat Formula "X" times based on Number in Cell
    By waltheaj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2013, 12:24 PM
  6. How to repeat a macro x number of times based on a value in a cell
    By gypsyhotelier in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2011, 05:11 PM
  7. Repeat values based on number count (without macro)
    By ibexcel in forum Excel General
    Replies: 7
    Last Post: 12-17-2009, 06:35 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