如何使用VBA将公式输入单元格? [英] How to enter a formula into a cell using VBA?
本文介绍了如何使用VBA将公式输入单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码是:
工作表(EmployeeCosts)。Range(B& var1a ).Formula =SUM(H5:H& var1a)
但它进入
解决方案
您没有正确构建公式。
工作表(EmployeeCosts)。Range(B& var1a).Formula == SUM(H5:H& var1a&)
这与以下行一样:
Dim myFormula As String
myFormula == SUM(H5:H
myFormula = myFormula& var1a
myformula = myformula& )
这是你想要做的。
另外,您希望在formala的开头有 =
。
I am trying to enter a formula into a cell which contains variable called var1a? The code that I have is:
Worksheets("EmployeeCosts").Range("B" & var1a).Formula = ""SUM(H5:H""& var1a)
But it enters into an excel worksheet with a mistake.
解决方案
You aren't building your formula right.
Worksheets("EmployeeCosts").Range("B" & var1a).Formula = "=SUM(H5:H" & var1a & ")"
This does the same as the following lines do:
Dim myFormula As String
myFormula = "=SUM(H5:H"
myFormula = myFormula & var1a
myformula = myformula & ")"
which is what you are trying to do.
Also, you want to have the =
at the beginning of the formala.
这篇关于如何使用VBA将公式输入单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文