Hi!
I have made an iterative process in VBA, which gives the angle of a perfect circular circle between to points with North South coordinates(X) and East West coordinates(Y). The Depth is of no interest in this case, so there is no Z coordinate.
What I need is the solver to do is continue down i = i+1, meaning the constraints change down one cell as well as the target cell and the cell needed for change. In this case the target cell and the cell needed for change is the same.
The code is here and is written in excel2007, meaning the add-in for solver is written like "solver.xlam".
I have made an iterative process in VBA, which gives the angle of a perfect circular circle between to points with North South coordinates(X) and East West coordinates(Y). The Depth is of no interest in this case, so there is no Z coordinate.
What I need is the solver to do is continue down i = i+1, meaning the constraints change down one cell as well as the target cell and the cell needed for change. In this case the target cell and the cell needed for change is the same.
The code is here and is written in excel2007, meaning the add-in for solver is written like "solver.xlam".
Code:
Private Sub CommandButton1_Click()
SolverMacro
End Sub
Sub CheckCells()
Dim Data As Range
For Each Data In Range("A1:B20")
If IsEmpty(Data.Value) Then
ElseIf WorksheetFunction.IsText(Data.Value) Then
MsgBox "There is text written in the cells - remove!!!"
ElseIf WorksheetFunction.IsNumber(Data.Value) Then
SolverMacro
End If
Next Data
End Sub
Sub SolverMacro()
Application.Run "solver.xlam!Solver.Solver2.Auto_open"
Application.Run "SolverReset"
Application.Run "SolverAdd", "E3", 1, "F3"
Application.Run "SolverOk", "G3", 1, "0", "G3"
Application.Run "SolverSolve", True
End Sub
[\code]
This code in Solver says E3=F3 by changing G3 to achieve the angle and place it in G3. This happens when the commandbutton1_click is run, and the cell is not empty by initiating the CheckCells(), which again starts the SolverMacro() routine.
E3=(X-Xo)/(Y-Yo) ->where X is the new coordinate while Xo is the one before, and the same for Y and Yo. Xo is C2, X is C3, Yo is D2, Y is D3
F3 = (sinφ-sinφo)/ (cosφ-cosφo) -> where φ is the angle corrospondent with the coordinate of X and Y, and φo is corrospondent with the coordinates Xo and Yo. φo is the known cell G2 and φ is the iterative solution G3 of the angle for the circular arc between the two points.
So the solver changes G3 till E3=F3 and thus making it an iterative solution. How can I make the code so that it continues to calculate E4=F4 by changing G4. Have tried making an object and doing i = i+1, but I fail again and again. Maybe some of you have a solution? I could make a commandbutton for each row, but I have like 40 rows, so I would very much like to have only one commandbutton doing the CheckCell() and when there is a number inside the X and Y the SolverMacro() is initiated. Any suggestions??
Hope I am explaining well enough what I want? The way I see it is the SolverMacro() which need to be changed, with some i = i+1 and so forth.... Hope you could help me. I am really stuck here and it would simplify my workbook a lot!
Greetings from Norway:)
Haakon Martin