+ Reply to Thread
Results 1 to 8 of 8

Looping a Formula?

  1. #1
    Registered User
    Join Date
    02-23-2005
    Location
    UK
    MS-Off Ver
    2007
    Posts
    18

    Question Looping a Formula?

    Hi,

    Apologies if this is quite a simple query, however VBA is very new to me.

    I am wanting to loop my formula so that when my marco button is pressed, the formula will run in the same cell 50 times.

    The formula is for a random name selector and I am wanting to achieve the impression that the selector is cycling through the list of names until it stops running after the 50th time.

    So far I have the following macro which is working:

    Sub Enter_Formulas()
    Range("D4").Formula = "=ROUND((RAND()*'List'!C4)+0.5,0)"


    End Sub

    How do I now go about looping this?

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,732

    Re: Looping a Formula?

    Put a FOR ... NEXT loop around it, like this:

    Please Login or Register  to view this content.
    In future you should put Code tags around your snippets of code - select the code while you are editing, then click on the # symbol above.

    Hope this helps.

    Pete
    Last edited by Pete_UK; 11-29-2016 at 11:12 AM.

  3. #3
    Registered User
    Join Date
    02-23-2005
    Location
    UK
    MS-Off Ver
    2007
    Posts
    18

    Re: Looping a Formula?

    Thanks Pete. I have updated my module with the above, however now when I run the Marco, loads the "Open File" window each time before completing the calculation. Any idea how to get around this?

    Thanks for the advice about the code tags

    Dan

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,732

    Re: Looping a Formula?

    There is nothing in that code that should cause the Open File dialogue to open. Perhaps you have something else in your module?

    Pete

  5. #5
    Registered User
    Join Date
    02-23-2005
    Location
    UK
    MS-Off Ver
    2007
    Posts
    18

    Re: Looping a Formula?

    Hi Pete,

    My module now reads as follows:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-23-2005
    Location
    UK
    MS-Off Ver
    2007
    Posts
    18

    Re: Looping a Formula?

    The Dialogue box which opens says "Update Values: List" at the top of the window

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Looping a Formula?

    I agree with Pete, I don't see anything that should trigger a dialogue box or an open box or anything else. I put your code into a new, blank workbook, and it seems to work just fine with no dialogs. Something else is going on.
    Attached Files Attached Files
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,732

    Re: Looping a Formula?

    The only way I can reproduce that is if the sheet that is named List has a space (or more) at the end of the name. Double-click on the tab and type List again without any spaces, then you can re-run the macro.

    Hope this helps.

    Pete

+ 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. looping through worksheet and enter formula
    By CostCare in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-29-2016, 09:04 AM
  2. [SOLVED] Is there a way to put the vlookup formula without looping involve?
    By emina002 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-27-2014, 10:54 PM
  3. looping a formula
    By ceejay22 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2013, 07:25 PM
  4. Looping Formula Help
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 05:56 AM
  5. [SOLVED] Looping an index transposing formula
    By poetgirl916 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-22-2013, 01:52 PM
  6. Looping through cells setting a formula
    By JonPugh in forum Excel General
    Replies: 1
    Last Post: 01-08-2010, 12:04 PM
  7. Looping of repeatitive formula
    By Chetan Chauhan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2009, 03:03 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