【问题标题】:How to enter a formula in a cell that references the sheet name from a string variable?如何在引用字符串变量的工作表名称的单元格中输入公式?
【发布时间】:2021-01-30 20:51:42
【问题描述】:

我的 VBA 在单元格中输入公式。此公式引用了另一张纸。

我想用字符串变量替换工作表名称“13) Friends Mailer”,因此公式引用了我选择的工作表。

ActiveCell.FormulaR1C1 = _
  "=VLOOKUP(RC[-2],'13) Friends Mailer'!R6C1:R90C15,14,0)+VLOOKUP(RC[-2],'13) Friends Mailer'!R6C1:R90C15,15,0)"

我试过了:

ActiveCell.FormulaR1C1 = _
  "=VLOOKUP(RC[-2],'" &worksheetName& "'!R[4]C[-9]:R[88]C[5],14,0)+VLOOKUP(RC[-2],'13) Friends Mailer'!R[4]C[-9]:R[88]C[5],15,0)"

【问题讨论】:

标签: vba excel


【解决方案1】:

替换:

"=VLOOKUP(RC[-2],'" &worksheetName&

与:

"=VLOOKUP(RC[-2],'" & worksheetName &

(可能还有其他问题)

【讨论】:

    【解决方案2】:
    txt = "13) Friends Mailer"
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-2],'" & txt & "'!R6C1:R90C15,14,0)+VLOOKUP(RC[-2],'" & txt & "'!R6C1:R90C15,15,0)"
    

    【讨论】:

      猜你喜欢
      • 2019-05-07
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多