Question : Macro to run Goal Seek multiple times and transpose output - Excel 2007

Hello,
I have attached a sheet in which I am running Goal Seek.

My 'Set Cell' is E19, which has the formula =ROUND(E17^2,2)
My 'to Value' is 1
My ' By Changing Cell' is E18, which has the formula =SUM(E6:E11)

I would like a macro (or other way) to run Goal Seek one thousand times (1,000).  I would like the result of each 'Goal Seek' to be copy and pasted, transposed, into sheet two.  I have shown four iterations.

I would appreciate annotated code.

Thank you kindly,
JE

Answer : Macro to run Goal Seek multiple times and transpose output - Excel 2007

I assume that you want to report the values in E6:E11 to worksheet Sheet 2. If so, the macro below will execute GoalSeek 1000 times for that purpose. It takes about 3 seconds to run on my laptop.

Brad
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Sub GoalSeeker()
Dim rgVals As Range, rgReport As Range, celGoal As Range, celVary As Range
Dim i As Long, n As Long
Dim dGoal As Double
dGoal = 1
With Worksheets("Sheet1")
    Set rgVals = .Range("E6:E11")
    Set celGoal = .Range("E19")
    Set celVary = .Range("E18")
End With
Set rgReport = Worksheets("Sheet 2").Range("C3:H3")
Set rgReport = rgReport.End(xlDown).Resize(1, rgReport.Columns.Count)
Application.ScreenUpdating = False
For i = 1 To 1000
    celGoal.GoalSeek dGoal, celVary
    rgReport.Rows(i + 1).Value = Application.Transpose(rgVals.Value)
Next
Application.ScreenUpdating = True
End Sub
Random Solutions  
 
programming4us programming4us