【问题标题】:Excel VBA to input formula followed by text into cell or cell formulaExcel VBA将公式后跟文本输入单元格或单元格公式
【发布时间】:2020-09-11 12:20:01
【问题描述】:

我的计数工作正常如下:

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

我希望单元格的计数后跟“方案”一词

我试过了

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

但失败了。我不确定引号。我也尝试过使用 + 和 AND,但也没有用。

【问题讨论】:

    标签: excel vba text formula cell


    【解决方案1】:

    请你这样试试:

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

    连接字符 (&) 必须在公式字符串内,并且在代码编写公式时,任何双引号都必须加倍。我还认为公式结果和结束字符串之间必须留一个空格...

    【讨论】:

      【解决方案2】:

      你可以使用With和两行:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        • 1970-01-01
        • 2022-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多