sake14
06-15-2015, 03:44 AM
Hello,
I am having a hard time at work implement the goal seek function.
I need to allow the code to run through cells that is why i use "i" as a counter.
Every time I try to run it it gives the message "Application defined or Object defined error"
and when I solve this it gives me the error message "range of object worksheet failed"
Any help please....
Thank you very much!!!
I am posting the code....
Sub pds()
Dim i As Long
i = 5
Do Until i = 2323
If Cells(i, 2) <> "" Then
Source = Worksheets(3).Cells(i, 12)
ResultCell = Worksheets(3).Cells(i, 14).Value
Result = Worksheets(3).Cells(i, 2).Value
Range(ResultCell).GoalSeek Goal:=Result, ChangingCell:=Range(Source)
ElseIf Cells(i, 3) <> "" Then
Source = Worksheets(3).Cells(i, 13)
ResultCell = Worksheets(3).Cells(i, 15).Value
Result = Worksheets(3).Cells(i, 3).Value
Range(ResultCell).GoalSeek Goal:=Result, ChangingCell:=Range(Source)
End If
i = i + 1
Loop
End Sub
I am having a hard time at work implement the goal seek function.
I need to allow the code to run through cells that is why i use "i" as a counter.
Every time I try to run it it gives the message "Application defined or Object defined error"
and when I solve this it gives me the error message "range of object worksheet failed"
Any help please....
Thank you very much!!!
I am posting the code....
Sub pds()
Dim i As Long
i = 5
Do Until i = 2323
If Cells(i, 2) <> "" Then
Source = Worksheets(3).Cells(i, 12)
ResultCell = Worksheets(3).Cells(i, 14).Value
Result = Worksheets(3).Cells(i, 2).Value
Range(ResultCell).GoalSeek Goal:=Result, ChangingCell:=Range(Source)
ElseIf Cells(i, 3) <> "" Then
Source = Worksheets(3).Cells(i, 13)
ResultCell = Worksheets(3).Cells(i, 15).Value
Result = Worksheets(3).Cells(i, 3).Value
Range(ResultCell).GoalSeek Goal:=Result, ChangingCell:=Range(Source)
End If
i = i + 1
Loop
End Sub