为什么我得到运行时错误13:输入错配错误 在运行以下代码时
Application.Goto Reference:="R1C1:R232C221"
Selection.FormulaArray = "=ROUND(a(),0)"
Selection.Replace What:="a()", Replacement:="IF(IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0," & _
"Sheet4!A1:HM232+Sheet5!A1:HM232)+IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0," & _
"Sheet4!A1:HM232+Sheet5!A1:HM232)=2,0,IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0," & _
"Sheet4!A1:HM232+Sheet5!A1:HM232)+IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0,Sheet4!A1:HM232+Sheet5!A1:HM232))", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Range("I9").Select
1)我知道公式阵列应该是R1C1风格......但是A1风格不是必需的,它在A1风格中也没有任何问题
http://msdn.microsoft.com/en-us/library/bb208529.aspx
2)我从
中找到了这种写作方式 http://www.dailydoseofexcel.com/archives/2005/01/10/entering-long-array-formulas-in-vba/
答案 0 :(得分:4)
让我们分析一下你的替代品:
Replacement:="IF(IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0," & _
"Sheet4!A1:HM232+Sheet5!A1:HM232)+IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0," & _
"Sheet4!A1:HM232+Sheet5!A1:HM232)=2,0,IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0," & _
"Sheet4!A1:HM232+Sheet5!A1:HM232)+IF(Sheet4!A1:HM232+Sheet5!A1:HM232=2,0,Sheet4!A1:HM232+Sheet5!A1:HM232))"
(1)将Sheet4!A1:HM232+Sheet5!A1:HM232
更改为X
:
Replacement:="IF(IF(X=2,0," & _
"X)+IF(X=2,0," & _
"X)=2,0,IF(X=2,0," & _
"X)+IF(X=2,0,X))"
(2)将破碎的碎片粘在一起:
Replacement:="IF(IF(X=2,0,X)+IF(X=2,0,X)=2,0,IF(X=2,0,X)+IF(X=2,0,X))"
(3)将IF(X=2,0,X)
更改为Y
:
Replacement:="IF(Y+Y=2,0,Y+Y)"
(4)一些评价:
(5)所以公式相当于:
Replacement:="IF(OR(X=2,X=1),0,2*X)"
(6)所以下一步是替换X(反向步骤1)...
我会给你留下一两个问题:它是如何变得如此混乱?你听说过“干”(不要重复自己)吗?
答案 1 :(得分:0)
我认为“替代”的论点太长了。您需要将该字符串保持在255个字符以下。将更多公式放入Selection.FormulaArray行,以便替换小于255个字符。