VBA help for minimizing a solution using multiple scenarios

bugarin1010

Board Regular
Joined
Jan 28, 2008
Messages
59
Hi,

First, thanks to everyone for reading my post. Here's my problem:

I have nearly two thousands variable cells with the equation randbetween(0,3). Based on the values in these cells, my solution changes. I want to run 250-or so scenarios to obtain the minimum value from these scenarios. Also, I want to be able to copy the solution result as well as the value of the variable cells so that I can re-create these results.

I'm currently on "manual update" so I want to use "F9" to re-calculate the solution cell since it will change the "randbetween" variable cells.

Here's the worksheet information:

Worksheet name: Results
Solution cell: B4
Variable cells: B7:B2000

I want to copy the solution cell starting in cell D4 and proceeding to E4, F4 all the way to IV4

At the same time, I want to copy the variable cells into E7:E2000 and proceeding to F7:F2000 all the way to IV7:IV2000.

Here's the VBA code that works great, except that it isn't moving to the next column to paste the results! :) Can someone help me correct it?


Code:
Sub Automation()

Dim i As Integer
Set Results = Sheets("Results")

Results.Activate

For i = 4 To 253
    
    Calculate
    Range("B4").Select
    Selection.Copy
    
    Range("D4") = Cells(4, i)
    Range("D4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("B7").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    
    Range("D7") = Cells(7, i)
    Range.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False

Next i

End Sub
Thanks!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi bugarin1010

Try:

Code:
Sub Automation()
Dim i As Integer
 
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
 
With Worksheets("Results")
    For i = 4 To 253
        
        Calculate
        
        .Cells(4, i).Value = .Range("B4").Value
    
        .Range(.Cells(7, i), .Cells(20000, i)).Value = .Range("B7:B20000").Value
        
    Next i
End With
 
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top