+ Reply to Thread
Results 1 to 10 of 10

Repeat macro and add next number to text box

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    44

    Repeat macro and add next number to text box

    I need to be able to add the next number to a text box which is a shape. When I run the macro the number 1 starts in the text, then the next time I run it I want the number 2, the next time number 3, number 4, 5, 6 etc.... I have the macro that can produce the first one but can't figure out how to loop it to add the next number.

    Please Login or Register  to view this content.
    Thanks

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Repeat macro and add next number to text box

    Hi jtemp57,

    Try the following (tested and working):
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,469

    Re: Repeat macro and add next number to text box

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,469

    Re: Repeat macro and add next number to text box

    Or, maybe a count down ...

    Please Login or Register  to view this content.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    08-21-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Repeat macro and add next number to text box

    This is on the right track; however, I don't want all of them to appear at once. If I assign it to a button, then every time I press the button I would want the next number to appear instead of all at once. I guess I would need something like i+1....???

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,469

    Re: Repeat macro and add next number to text box

    You need to manage incrementing the counter somehow, but ...

    Please Login or Register  to view this content.

    Regards, TMS

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Repeat macro and add next number to text box

    The following sequence of events should help you out (tested and working in Excel 2003). This should work for several shapes existing at the same time, without changing any code.

    1. Create a Macro that will increment the number in the Shape. The name can be any legal Macro name.
    Please Login or Register  to view this content.
    2. Assign the Macro to Exisiting Shapes
    Right Click the Shape > Assign Macro > MyOvalIncrement >OK

    3. Modify your creation Macro slightly, to assign the macro when you create the Shape. If the macro doesn't exist when you create the shape, but exists later, you may have to close the workbook, for the shape to recognize the Macro name. It is easier to have the macro exist when you create the Shape.
    Modifications to your code are in red:
    Please Login or Register  to view this content.
    Lewis
    Last edited by LJMetzger; 08-05-2014 at 09:46 AM.

  8. #8
    Registered User
    Join Date
    08-21-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Repeat macro and add next number to text box

    Ok, this one counts to the number I need from my range, but it doesn't create a new shape for each number, it just replaces the number in the shape?
    Please Login or Register  to view this content.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,469

    Re: Repeat macro and add next number to text box

    That's right. It doesn't create a new shape each time. You get it to do that by moving the
    Please Login or Register  to view this content.
    inside the loop. However, as it stands, each shape would be in the same place as all the others. If you want to create it elsewhere, you'd need to adjust the location parameters, perhaps based on the counter.

    Regards, TMS

  10. #10
    Registered User
    Join Date
    08-21-2013
    Location
    Louisiana
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Repeat macro and add next number to text box

    Yes!! That worked great!! Thanks so much

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,469

    Re: Repeat macro and add next number to text box

    You're welcome. Thanks for the rep.

+ 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] Need Macro to repeat number set
    By Latha Mani in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-09-2014, 08:19 AM
  2. Formula for count excel text & number except repeat
    By emran06 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-13-2014, 04:06 AM
  3. Replies: 8
    Last Post: 09-20-2013, 08:12 AM
  4. Need a macro to repeat a number from one row to the next row
    By peesh567 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 10:42 AM
  5. Repeat text in cells and add one to the number
    By kyleconnolly in forum Excel General
    Replies: 1
    Last Post: 02-16-2011, 10:16 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