|
-
May 27th, 2007, 05:01 PM
#1
Thread Starter
Frenzied Member
Goal Seek Iteration Code in VBA? Possible?
Hi there,
I have an iteration which I want to use the principle of goal seek totally in vba without using the in-built excel one. Is this at all possible?
Code:
Sub Iterate()
Dim row As Integer
Dim i As Integer
Dim temp As Single
Dim flowCo As Single
Dim flowExp As Single
Dim PressCo As Single
Dim OJ As Single
Dim total As Single
Dim X As Single
R = 100
'3.441062516
Do Until total < 0.01 And total > 0
'First need to calculate the O(J) Column
row = Me.ListBox1.ListCount
total = 0
For i = 0 To row - 1
temp = Me.ListBox1.List(i, 5)
Me.ListBox1.List(i, 6) = R + temp
'Now we calculate F(J)
flowCo = Me.ListBox1.List(i, 2)
flowExp = Me.ListBox1.List(i, 3)
PressCo = Me.ListBox1.List(i, 4)
OJ = Me.ListBox1.List(i, 6)
Me.ListBox1.List(i, 7) = flowCo * ((Abs(OJ) ^ flowExp) * (OJ / Abs(OJ)))
total = total + Me.ListBox1.List(i, 7)
Next
If total < 0 Then
R = R + 0.1
Else
If total > 1 Then
R = R ^ 0.5
ElseIf total > 0.1 Then
R = R - 0.1
ElseIf total > 0.01 Then
R = R - 0.01
End If
End If
Loop
MsgBox R
'Now we need to sum it up
End Sub
I have tried all kinds of Tweaks and it does not seem to work
please help!
If you find my thread helpful, please remember to rate me 
-
May 29th, 2007, 01:18 AM
#2
Fanatic Member
Re: Goal Seek Iteration Code in VBA? Possible?
-
May 29th, 2007, 10:22 AM
#3
Re: Goal Seek Iteration Code in VBA? Possible?
Or you could just call the GoalSeek method of the target cell.
Excel Developer Reference
Range.GoalSeek Method
Calculates the values necessary to achieve a specific goal. If the goal is an amount returned by a formula, this calculates a value that, when supplied to your formula, causes the formula to return the number you want. Returns True if the goal seek is successful.expression.GoalSeek(Goal, ChangingCell)
Return Value
Boolean
expression A variable that represents a Range object.
Parameters
Name Required/Optional Data Type Description
Goal Required Variant The value you want returned in this cell.
ChangingCell Required Range Specifies which cell should be changed to achieve the target value.
Example
This example assumes that Sheet1 has a cell named "Polynomial" that contains the formula =(X^3)+(3*X^2)+6 and another cell named "X" that’s empty. The example finds a value for X so that Polynomial contains the value 15.
Visual Basic for Applications
Worksheets("Sheet1").Range("Polynomial").GoalSeek _
Goal:=15, _
ChangingCell:=Worksheets("Sheet1").Range("X")
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|