Results 1 to 6 of 6

Thread: Can VBA record multiple iteration wb results with for next loop from a range of data?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    1. Big project

    2. An example workbook would help, along with some worked 'examples'

    3. Excel's Scenario Manager might be able to do it without VBA

    4.The easiest way might be to have a list of the gas prices, and a loop that uses each price on the other sheets to calculate, and then put the results on the Summary sheet

    The attachment has a simple example for some made up gas prices and dummied up data

    Option Explicit
    
    Sub Demo()
        Dim i As Long
        
        Application.ScreenUpdating = False
        
        With Worksheets("Summary")
            For i = 2 To .Cells(1, 1).CurrentRegion.Rows.Count
                Worksheets("E_current_no").Range("A2").Value = .Cells(i, 1).Value
                Worksheets("E_current_with").Range("A2").Value = .Cells(i, 1).Value
                
                Application.CalculateFull
                
                .Cells(i, 2).Value = Worksheets("E_current_no").Range("N3").Value
                .Cells(i, 3).Value = Worksheets("E_current_with").Range("N3").Value
                
            Next i
        End With
        
        Application.ScreenUpdating = True
        
        MsgBox "Done"
    
    End Sub
    There are other (and more elegant) ways to do it
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •