[英]Goal seek in VBA error "reference isn't valid"
I have a problem with the GoalSeek
function in Excel's VBA.我对 Excel 的 VBA 中的
GoalSeek
function 有疑问。
It says "reference isn't valid", and I know that it refers to the reference r
and c
, cause if I put in numbers instead, it runs smooth.它说“参考无效”,我知道它指的是参考
r
和c
,因为如果我输入数字,它运行顺利。
However, if I split up the code, I can see that r
=68 and c
=7, which is the correct numbers.但是,如果我拆分代码,我可以看到
r
=68 和c
=7,这是正确的数字。 So it's when the reference is put into the Cells
reference in the goal seek function it does not work and I get the error "reference isn't valid".因此,当引用被放入目标寻找 function 中的
Cells
引用时,它不起作用并且我收到错误“引用无效”。
Are there some kind of Dim
or Set
that I am missing?我缺少某种
Dim
或Set
吗?
Sub MacroTest1()
ActiveSheet.Calculate
r = Range("LeverageRatioPeriod").Row
c = WorksheetFunction.Match(Range("MaxAcquisitionYear"), Range("YearRange"), 0)
Cells(r, c).GoalSeek Goal:=4, ChangingCell:=Range("MaxEV")
Please check what is entered in the cell Range("MaxEV").请检查单元格 Range("MaxEV") 中输入的内容。 If there is a formula there, please replace it with a simple value.
如果那里有公式,请将其替换为简单的值。 In my case, this resolved a similar issue, and GoalSeek finally returned a value.
就我而言,这解决了一个类似的问题,GoalSeek 最终返回了一个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.