简体   繁体   English

Excel VBA将公式后跟文本输入单元格或单元格公式

[英]Excel VBA to input formula followed by text into cell or cell formula

I have the count working fine as below:我的计数工作正常,如下所示:

Sheet2.Range("A1").End(xlDown).Offset(1, 3).FormulaR1C1 = "=COUNTA(R2C:R[-1]C)"

I want the cell to have the count followed by the word "Schemes"我希望单元格的计数后跟“方案”一词

I have tried我试过了

Sheet2.Range("A1").End(xlDown).Offset(1, 3).FormulaR1C1 = "=COUNTA(R2C:R[-1]C)"  & "Schemes"

but fails.但失败了。 I am not sure about the quototation marks.我不确定引号。 I also tried using + and AND but also not working.我也尝试使用 + 和 AND 但也没有工作。

Please, try it in this way:请以这种方式尝试:

Sheet2.Range("A1").End(xlDown).Offset(1, 3).FormulaR1C1 = "=COUNTA(R2C:R[-1]C)&"" Schemes"""

The concatenation character ( & ) must be inside the formula string and any double quotes must be doubled when the code writes the formula.连接字符 ( & ) 必须在公式字符串内,并且在代码编写公式时任何双引号都必须加倍。 I also thought that a space must be let between the formula result and the ending string...我还认为必须在公式结果和结束字符串之间留一个空格...

You can use With and two lines:您可以使用With和两行:

With Sheet2.Range("A1").End(xlDown).Offset(1, 3)
.FormulaR1C1 = "=COUNTA(R2C:R[-1]C)"
.Value = .Value & "Schemes"
End With

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

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