ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   GoalSeek in VBA (https://www.excelbanter.com/excel-discussion-misc-queries/100206-goalseek-vba.html)

[email protected]

GoalSeek in VBA
 
When if running this code I get the following error, anyone who know
what the problem is?

Error:
"Method 'Range' of object '_Global' failed"


Sub GoalSeekMacro()

Source = Worksheets("Olie og gas").Cells(9, 15).Value
ResultCell = "n9"
Result = 20
Range(ResultCell).GoalSeek goal:=Result,
ChangingCell:=Range(Source)

End Sub


Muhammed Rafeek M

GoalSeek in VBA
 
Hi

Use below mentioned macro:

Sub GoalSeekMacro()

Dim rngS As Range
Dim rngD As Range
Set rngS = Range("O8")
Set rngD = Range("N9")
Result = 20
rngD.GoalSeek Goal:=Result, ChangingCell:=rngS

End Sub



" wrote:

When if running this code I get the following error, anyone who know
what the problem is?

Error:
"Method 'Range' of object '_Global' failed"


Sub GoalSeekMacro()

Source = Worksheets("Olie og gas").Cells(9, 15).Value
ResultCell = "n9"
Result = 20
Range(ResultCell).GoalSeek goal:=Result,
ChangingCell:=Range(Source)

End Sub




All times are GMT +1. The time now is 09:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com