简体   繁体   中英

How to assign the cell in the formula?

I have created VBA that opens another excel and takes value from another cells. 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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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