简体   繁体   English

VBA目标搜寻是在不更改参数的情况下将单元格设置为0

[英]VBA Goal seek is setting cells to 0 without changing the argument

I'm tearing my hair out here. 我在这里扯头发。

When I run the goal seek in the worksheet it's fine. 当我在工作表中运行目标搜索时就可以了。 When I try to run the exact same goal seek from vba (recorded or coded by hand) the cell I'm supposed to be goal seeking displays as 0 and the variable does not change. 当我尝试从vba(手动记录或编码)运行完全相同的目标搜索时,我应该作为目标搜索的单元格显示为0,并且变量不变。 F9 does nothing. F9不执行任何操作。 If I edit the goalseek cell, to force it to recalculate, it displays the original output again - because nothing has changed. 如果我编辑goaleekeek单元以强制其重新计算,它将再次显示原始输出-因为没有任何更改。

Has anyone else encountered this? 有人遇到过这种情况么?

Range("G14").GoalSeek Goal:=0, ChangingCell:=Range("F14")

G14 is a user defined formula with 2 range arguments and a couple of single cell arguments. G14是用户定义的公式,具有2个范围参数和几个单单元格参数。

F14 is a cell inside one of the range arguments, and is definitely a driver in the calculation. F14是范围参数之一内的单元格,并且绝对是计算中的驱动器。

Try running it as 尝试以

DoEvents
ActiveSheet.Range("G14").GoalSeek Goal:=0, ChangingCell:=ActiveSheet.Range("F14")

Not sure if it's materially different from your existing code, but might go through correctly. 不知道它与您现有的代码是否有实质性的区别,但是可能会正确通过。

Also try running your goalseek on the spreadsheet manually while recording a macro and see the auto-generated macro code if something odd is happening. 另外,在记录宏的同时尝试在电子表格上手动运行Goaleek,如果发生奇怪的情况,请查看自动生成的宏代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM