GoalSeek in VBA

A

alundlarsen

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
 
M

Muhammed Rafeek M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top