【问题标题】:How to use variable string in index formula in VBA?如何在 VBA 的索引公式中使用变量字符串?
【发布时间】:2017-04-15 21:03:56
【问题描述】:

我想在 VBA 中编写 INDEX 公式时参考另一个工作簿。这些是我正在遵循的步骤:

将 myFilePath 调暗为字符串,将 myFileName 调为字符串,将 mySheetName 调暗为字符串

  1. myFilePath = inputbox("写入路径")
  2. myFileName = inputbox ("写名字")
  3. mySheetName = inputbox ("写下工作表名称")
  4. Range("CA1").Select
    ActiveCell.FormulaR1C1 = _
    "=INDEX('myFilePath[myFileName]mySheetName'!R1C1:R100C1,MATCH(RC[-53],'myFilePath[myFileName]mySheetName'!R1C8:R800C8,0))"

但是,公式不接受变量 myFilePath、myFileName 和 mySheetName。有什么我遗漏的吗?

【问题讨论】:

  • 当你在 A1 时,如何要求匹配 RC[-53]
  • 我的错。是CA1。 (已编辑)无论如何,我被困在如何在 INDEX 公式中使用变量字符串!

标签: excel vba indexing vlookup


【解决方案1】:

试试看,

Range("CA1").Select
ActiveCell.FormulaR1C1 = _
  "=INDEX('" & myFilePath & "[" & myFileName & "]" & mySheetName & "'!C1, MATCH(RC[-53],'" & myFilePath & "[" & myFileName & "]" & mySheetName & "'!C8, 0))"

【讨论】:

    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    相关资源
    最近更新 更多