I tried to use looping with the goal seek in excel but cannot work, would you please correct the code below
Private Sub CommandButton1_Click()
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Integer
i = 5
Do While Cells(i, 9) <> ""
Cells(i, 7).Value = Range("H5").GoalSeek Goal:=Range("I5").Value, ChangingCell:=Range("A5")
i = i + 1
Loop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Remove "Cells(i, 7).Value =" from the below line.
Return type of goal seek is Boolean.
value is a variant.
Range("H5").GoalSeek Goal:=Range("I5").Value, ChangingCell:=Range("A5")
Finally I get the solution for this issue, just to get the benefit of it all please see below answer.
Private Sub GoalSeek()
Dim i As Long
For i = 4 To 6
Range("H" & i).GoalSeek Goal:=Range("I" & i).Value, ChangingCell:=Range("A" & i)
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.