在VBA中应用公式? [英] Apply formula in VBA?
本文介绍了在VBA中应用公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试应用一个在单元格中写入YES或NO的公式来检查另一个单元格是否以Q)文本开头。
在Excel中手动编写它正在工作
= IF(LEFT(A2; 2)=Q);YES;NO)
但是当我尝试在宏中自动执行
公式== IF(LEFT(A2; 2)=Q);是;否 )
运行时错误'1004':应用程序定义或对象定义的错误
此外,我想要为整个列执行此操作
范围(R2:R& lastRow).Formula == IF(LEFT(A2; 2)=Q); YES;NO)
但是我必须先解决问题之前。
我做错了什么?
解决方案
VBA使用逗号分隔符,无论您的本地设置如何
Range(R2:R& lastRow).Formula == IF(LEFT(A2,2)=Q),YES, NO)
I am trying to apply a formula that writes YES or NO in a cell checking if another cell starts with Q) text.
Writing it manually in Excel is working.
=IF(LEFT(A2;2)="Q)";"YES";"NO")
But when I try to do it automatically inside a macro
Range("R2").Formula = "=IF(LEFT(A2;2)=""Q)"";""YES"";""NO"")"
Run-time error '1004': Application-defined or object-defined error
Also, I will want to do it for the whole column, something like this
Range("R2:R" & lastRow).Formula = "=IF(LEFT(A2;2)=""Q)"";""YES"";""NO"")"
But for that I have to solve the first problem before.
What am I doing wrong?
解决方案
VBA uses the comma separator, irrespective of your local settings
Range("R2:R" & lastRow).Formula = "=IF(LEFT(A2,2)=""Q)"",""YES"",""NO"")"
这篇关于在VBA中应用公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文