[英]Excel VBA: inserting WHEN formula into specific range of cells with variable changing column
Hello dear StackOverflow users, 您好亲爱的StackOverflow用户,
My issue is regarding inserting a Formular via Macro into specific range of cells. 我的问题是关于通过宏将Formular插入特定范围的单元格。 Again, again and again. 一次又一次。
So the Basic function of the formula should be the following: 因此,公式的基本功能应为:
=WHEN('ZEK '!F3="X";"6";WHEN('ZEK '!G3="X";"8";"1"))
In my macro it has to Change the column for the next specific range. 在我的宏中,必须将列更改为下一个特定范围。 This is Happening in a for Loop for i
growing. 对于i
这正在for循环中发生。
meaning --> =When('ZEK '!$F$"& i+2 &".......
or in any other Syntax that should work. My try fairly does not, thats why I need your help. 意思是-> =When('ZEK '!$F$"& i+2 &".......
或其他应该起作用的语法。我的尝试完全没有,这就是为什么我需要您的帮助。
This is my Initial try where i exchanged literally everything with strings: 这是我的最初尝试,在这里我实际上用字符串交换了所有内容:
Sub 123()
Dim a,b,c As String
a = 1
b = 6
c = 8
....
'used and declared variables k, x, f, a, b, c
Range(Cells(k + 2, 5), Cells(k + 27, 5)).FormulaR1C1 = _
"=WHEN('ZEK'!$F$" & f & "=" & x & ";" & a & ";WHEN('ZEK'!$G$" & f & "=" & x & ";" & b & ";" & c & "))"
End Sub
With that i get Runtime Error 1004. (changed it to .Formula from .FormulaR1C1) 有了它我得到运行时错误1004。(将其从.FormulaR1C1更改为.Formula)
I hope i gave enough Information, so that you could help me. 希望我能提供足够的信息,以便您可以帮助我。 This really does not have to be performant, i just Need to get the formula into about 100.000 cells with i
changing for each Range of cells 这实际上不一定是高性能的,我只需要将公式放入大约100.000个单元格中, i
就每个单元格范围都进行了更改
I think it's a language problem... Try 我认为这是语言问题...尝试
"=IF('ZEK'!$F$" & f & "=" & x & "," & a & ",IF('ZEK'!$G$" & f & "=" & x & "," & b & "," & c & "))"
Notice the use of IF
and ,
as a delimiter instead of ;
注意使用IF
和,
作为分隔符来代替;
. 。 Is WHEN
even a valid worksheet function? WHEN
有效的工作表功能? To be honest I don't know if the worksheet functions get translated or not when setting the formula via VBA. 老实说,我不知道通过VBA设置公式时工作表函数是否被翻译。 The delimiters are adapted though. 分隔符虽然可以修改。
edit: there is also the .FormulaLocal
property that should work with ;
编辑:还有.FormulaLocal
属性应与;
一起使用;
as delimiter! 作为分隔符! So change .Formula
to .FormulaLocal
. 因此,将.Formula
更改为.FormulaLocal
。 This will probably cause an error if you execute it on a machine that uses ,
as default delimiter so I'd try to stick with .Formula
. 如果在使用默认分隔符的计算机上执行它,可能会导致错误,
因此我将尝试使用.Formula
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.