admin管理员组

文章数量:1129155

I am trying to automate Goal Seek functions across a large number of data sets weherein the Rate is to be derived (through Goal Seek) such that the NPV at that rate is equal to the Target NPV.

This might be a very basic query, but I ll still ask : I am getting a Syntax error in running the Do Until Loop. My code is as follows:

Sub Macro3()

Do Loop Until Range("Target_NPV_Delta") = 0

Range("Target_NPV").GoalSeek Goal:=Range("NPV_Calc"), ChangingCell:=Range("Rate")
    
Loop
    
End Sub

I am able to srite the code without the range function. But moment i introduce range function, it shows Compile Error.

I am trying to automate Goal Seek functions across a large number of data sets weherein the Rate is to be derived (through Goal Seek) such that the NPV at that rate is equal to the Target NPV.

This might be a very basic query, but I ll still ask : I am getting a Syntax error in running the Do Until Loop. My code is as follows:

Sub Macro3()

Do Loop Until Range("Target_NPV_Delta") = 0

Range("Target_NPV").GoalSeek Goal:=Range("NPV_Calc"), ChangingCell:=Range("Rate")
    
Loop
    
End Sub

I am able to srite the code without the range function. But moment i introduce range function, it shows Compile Error.

Share Improve this question edited Jan 8 at 13:41 Shrotter 6301 gold badge5 silver badges16 bronze badges asked Jan 8 at 10:31 nikhil kshirsagarnikhil kshirsagar 1 New contributor nikhil kshirsagar is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

That is the wrong syntax for Do it should read

Sub Macro3()

   Do Until Range("Target_NPV_Delta") = 0

      Range("Target_NPV").GoalSeek Goal:=Range("NPV_Calc"), 
      ChangingCell:=Range("Rate")

   Loop

End Sub

本文标签: excelSyntax error in Macro Function seeking Goal SeekStack Overflow