简体   繁体   中英

VBA, referencing the name of another Sheet in Excel formula

I have a cell with this formula, =H4-'20200619'!H4 I need to change the formula daily. =H4-'nameAnotherSheet'!H4

For Example, in the C2 I want to store the name of another Sheet, with value 'nameAnotherSheet' .

Now I need to do some thing like =H4-'C2'!H4 but is not working!

How, I do the reference of another name sheet in the formula?

Now C2 cell has the name Sheet.

=H4-INDIRECT($C$2&"!H4") .

You can refer to a sheet or address by its name

=INDIRECT("Sheet name!A1",TRUE)

Not sure how you want to trigger it, or how to determine the sheet name each time, but since that isn't your question, here's how to treat a sheet name as a variable in your formula:

Range("A1").Formula = "=H4-'" & sSheetName & "'!H4"

If C2 has the name of the sheet....

Range("A1").Formula = "=H4-'" & Range("C2").Value & "'!H4"

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