简体   繁体   中英

Use concatenated string in Excel formula to get the cell value

I have a sheet named Vessel Reading 1. I want to read the value of the cell D4 into another sheet. 'Vessel Reading 1'!D4 gives me the value properly.

But, I want to be able to get the latest number instead of just 'Vessel Reading 1'. Eg if I have five sheets named 'Vessel Reading 1 to 5', I want to read the value from sheet named 'Vessel Reading 5'. Basically, 'Vessel Reading 1'!D4 should be changed to 'Vessel Reading N'!D4 where N is the latest sheet.

CONCATENATE("Vessel Reading ",RIGHT(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))),1))

Above sheet gives me the sheet name that I want. Eg if I am in sheet 5, it gives me 'Vessel Reading 5', and if I am in sheet 2, it gives me 'Vessel Reading 2'.

So, clearly, most of the work is already in place. Sadly, when I use

'CONCATENATE("Vessel Reading ",RIGHT(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))),1))'!D4

it throws an error. Now I am not sure what am I missing in this formula.

Edit:

Basically, I need a way to put the result of concatenate as a string to create cell reference.

If you place your formula for the sheet name in A1 then you can use this formula to find out value of D4 cell from that sheet.

=INDIRECT(CONCATENATE("'",A1,"'!D4"))

You can replace the A1 in the formula above with the code you created to find out the sheet and all will be in single formula. Full formula would look like

=INDIRECT(CONCATENATE("'",CONCATENATE("Vessel Reading ",RIGHT(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))),1)),"'!D4"))

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