简体   繁体   English

如何分配公式中的单元格?

[英]How to assign the cell in the formula?

I have created VBA that opens another excel and takes value from another cells.我创建了 VBA,它可以打开另一个 excel 并从另一个单元格中获取值。 I use index, indirect function:我使用索引,间接函数:

 ActiveCell.FormulaR1C1 = _
 "=IF(RC[-13]=0,"""",IFERROR(INDEX(INDIRECT(""'[excel 2020 07 BB_v1.xlsm]""&MID(CELL(""filename"",R1C1),FIND(""]"",CELL(""filename"",R1C1))+1,255)&""'!$N$2:$N$512""),MATCH(RC[-13],INDIRECT(""'[excel 2020 07 BB_v1.xlsm]""&MID(CELL(""filename"",R1C1),FIND(""]"",CELL(""filename"",R1C1))+1,255)&""'!$A$2:$A$512""),0)),""N/A""))"
   Range("N2").Select

I want to assign the cell with the excel name that I will not need to change every time the title of the name (excel 2020 07) in the code.我想为单元格分配excel名称,每次代码中的名称标题(excel 2020 07)都不需要更改。 Could you please help me?请你帮助我好吗?

Thank you谢谢

Concatenate strings (and variables) with & :使用&连接字符串(和变量):

ActiveCell.FormulaR1C1 = "=IF(RC[-13]=0,"""",IFERROR(INDEX(INDIRECT(""'[" & Range("N2").Value & " BB_v1.xlsm]""&MID

You might benefit from reading How to avoid using Select in Excel VBA .您可能会从阅读如何避免在 Excel VBA 中使用 Select 中受益。

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

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