Results 1 to 6 of 6

Nested Loops

Threaded View

  1. #6
    Registered User
    Join Date
    08-24-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Nested Loops

    I've managed to solve this using 2 For Next Loops instead. Here's the code if anyone else finds it of any use (as I have done to the solutions of many other threads). The basic principle is to loop a series of functions that are already looped. One use of this is for Monte Carlo type procedures where you loop a series of calculations to emulate a market phase. All calculations for the market are done per row, and this is repeated for each row using the inner calcLoop. This then needs to be queried a large number of times to test the rigidity of the market.

    Option Explicit
    
    Sub multiple_calc()
    Dim theCell As Range
    
    Dim outerLoop As Integer
    Dim Row As Long
    Dim calcLoop As Integer
        
        
      For outerLoop = 1 To 100000
    
        For calcLoop = 1 To 5
         
        
         Row = Row + 1
         
         Set theCell = Sheets("Sheet1").Cells(Row + 1, "G")
            With theCell
             
            .FormulaR1C1 = theCell.Value + 5
            .Calculate
            
             .Offset(0, 1).FormulaR1C1 = theCell.Value + 3
            .Calculate
            
            .Offset(0, 2).FormulaR1C1 = theCell.Value + 1
            .Calculate
            
            End With
           
        Next calcLoop
        Row = 0
     
     Next outerLoop
        
    End Sub
    Last edited by Walter12; 10-06-2012 at 07:34 AM.

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