+ Reply to Thread
Results 1 to 4 of 4

Loop Macro for Simulation

  1. #1
    Registered User
    Join Date
    05-02-2010
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Exclamation Loop Macro for Simulation

    Hello all,

    I am by no means new to Excel, but i am very new to writing code for macros... I am working on a side project that I need to use ONLY the resources available to me at home. I use SAS frequently at work, and I know how to do this in SAS, but I can't use my work resources for personal use ...

    I am running a bit of a simplified Monte Carlo simulation using random normal variables to calculate the price of a commodity based upon historical information and trends... What i am doing is simulating a certain number of prices, and calculating an average... This average is considered 1 "trial". I want to "paste special" this average into a cell as Trial 1, and then recalculate and "paste special" the next simulated average into a cell for trial two. I want this to loop for 1000+ trials...

    Here is a little bit of code showing what i want the macro to do... just paste a value, move down one cell and paste the next simulated value. Can anyone add to this macro to make it loop until i get to a specified number of trials??

    Thanks so much!!

    Please Login or Register  to view this content.
    *** since the RAND() function recalculates with every cell change or function, there's no need to re-calculate...
    Last edited by davesexcel; 05-02-2010 at 07:01 PM. Reason: Code tags required for VBA Code, Please read the Forum Rules

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop Macro for Simulation

    Hi,
    How about something like:

    Please Login or Register  to view this content.
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-02-2010
    Location
    PA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Loop Macro for Simulation

    Quote Originally Posted by Richard Buttrey View Post
    Hi,
    How about something like:

    Please Login or Register  to view this content.
    HTH
    THanks! I'll give it a shot and see what i come up with.... i don't think i'll get to til tomorrow night, but we'll see how it goes....

    Thanks again!

  4. #4
    Registered User
    Join Date
    10-03-2012
    Location
    Austin, US
    MS-Off Ver
    Excel 2010`
    Posts
    1

    Re: Loop Macro for Simulation

    Hello Guys,

    I'm doing something similiar. I was given an excel spreadsheet which calculates the price of stock and the value of random stock every year for 37 years based on the geometric brownian motion model. Every time I press F9 excel runs a new simulation in which the prices of stock change every year. I'm supposed to write a macros that does 1000 simulations and finds the average of the stock price in year 37 over those 1000 simulations (Add the resulting value of cell F39 for every of the 1000 simulations(everytime I press F9) and divide it by 1000). I have no clue on how to set up this loop, I've done simple loops using pseudo code in excel VBA but nothing like this.

    Please Help!!!!!!!!!!!

+ 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