+ Reply to Thread
Results 1 to 8 of 8

Help recording simulated output

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-11-2007
    Posts
    127

    Help recording simulated output

    I have created a simulation that outputs it's result to B18. The simulated results are created using the RAND() formula and so I press F9 to re-run the simulator.
    I would like to run this simulation 100 times and output the results in a table so I can find the average result.

    Is there a way of re-running this simulator 100 times and collating the results in a table without having to manually press F9 myself and copy and paste the result
    to the table?

  2. #2
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Help recording simulated output

    Maybe like this

    Sub ctest()
    Dim i As Long
    For i = 1 To 100
        Calculate
        Range("C" & i).Value = Range("B18").Value
    Next i
    End Sub

  3. #3
    Forum Contributor
    Join Date
    01-11-2007
    Posts
    127

    Re: Help recording simulated output

    Ok thanks, I'm gonna have to look into this as never tried to write any VB code. I created a module in the VB Editor and pasted the code, but havent a clue where to go from there to make it work.

    Can anyone point me in the right direction for a good VB learning resource so I can learn the basics and make sense of the code?

  4. #4
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Help recording simulated output

    Once you have entered the code, return to your sheet, press ALT + F8, double click ctest. Results in column C.

  5. #5
    Forum Contributor
    Join Date
    01-11-2007
    Posts
    127

    Re: Help recording simulated output

    Thanks Thalassa that's very useful. I just tried to adapt the code so that it outputs the results to E19:E1018. I changed the code to this:

    Sub ctest()
    Dim i As Long
    For i = 1 To 1000
    Calculate
    Range("E19:E1018" & i).Value = Range("B18").Value
    Next i
    End Sub

    ...but it gave some strange results. How can I make it put the results in E19:E1018 ?

  6. #6
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Help recording simulated output

    Try

    Sub ctest()
    Dim i As Long
    For i = 1 To 1000
        Calculate
        Range("E" & i + 18).Value = Range("B18").Value
    Next i
    End Sub

  7. #7
    Forum Contributor
    Join Date
    01-11-2007
    Posts
    127

    Re: Help recording simulated output

    Thanks again Thalassa. Here's an update to the code where it now enters the info in Column H

    Sub ctest()
    Dim i As Long
    For i = 1 To 250
    Calculate
    Range("H" & i + 6).Value = Range("B18").Value
    Next i
    End Sub

    If I wanted to do the same thing for B13 and output the results to Column E how could I add to this code? I could just create another macro, but I'd like to have one macro do the whole operation.

  8. #8
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Help recording simulated output

    Try this

    Sub ctest()
    Dim i As Long
    For i = 1 To 250
        Calculate
        Range("H" & i + 6).Value = Range("B18").Value
        Range("E" & i + 6).Value = Range("B13").Value
    Next i
    End Sub

+ 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