Excel INDIRECT function to another sheet that has a quote - excel-formula

This may seem like a very simple question, but I don't know the answer. I've searched thoroughly over and over. How can you use the INDIRECT function on a sheet that has a single quote on its sheet name? For example, if your sheet name is Test'Sheet, I can't write the formula properly and always returns #REF.
(Edit: For example, the name of the sheet is located on cell A1 of the active sheet. The name of the sheet is Test'Sheet (or anything that has a quote in it). I used the below formula, but didn't work.
=INDIRECT("'"&SUBSTITUTE(A1,"'",CHAR(34))&"'!A5",TRUE)
Of course I tried =INDIRECT("'"&A1&"'!A5",TRUE) too but that failed as well.
Thanks,
Jonathan Handojo

When a sheet name contains a single quote, you will need to escape the single quote by repeating it, e.g. 'Test''Sheet'!A5. For your example, the code would look like this:
=INDIRECT("'" & SUBSTITUTE(A1, "'", "''") & "'!A5", TRUE)

Related

Excel "INDIRECT" function with parameter from "CONCATENATE"

I am using an INDIRECT function to get value of a cell (B4) for many sheets in my workbook.
At the moment I have to hard code the name of the sheets like this
=INDIRECT("WCNEXP!$B$4")
Ideally I would like to find a way to compile the name "WCNEXP" with the help of the CONCATENATE formula, like this
=INDIRECT("CONCATENATE(B18,C18)!$B$4")
but it does not work for some reason.
Is there another way to get the name compiled from 2 cells and use the INDIRECT Formula ?
Photo of the workbook
Your code is almost good.
the quotes must be placed after the concatenate function, and with the use of "&" to join them.
=INDIRECT(CONCATENATE(B18,C18)&"!$B$4")

In excel can anyone show me how to concatenate strings and variables to make a cell reference?

If I manually reference a cell in another spreadsheet (by typing = in the destination cell and then clicking in the source spreadsheet), excel creates a formula like this: ='H:\excel\data\[source_file.xls]Sheet1'!$C$5
I am wanting to create that formula from the cell and path which are stored in cells in the destination spreadsheet (and some strings).
So I have in 3 cells B1:B3 in the destination spreadsheet these strings:
H:\excel\data\
source_file.xls
Sheet1!$c$5
Then, so far, I have placed this formula in the cell where I want the data from the source spreadsheet:
=B1&"["&B2&"]"&B3
Which evaluates to:
H:\excel\data\[source_file.xls]Sheet1!$c$5
Pretty close to what I need. But as you can see some single quotes are missing. If I try to put these in, excel seems to think I am giving it a defined name.
Is there perhaps some sort of escape character I should put before the quote to make it work?
I have searched this website and excel help files to no avail.
That is the end of the question but I anticipate that someone is going to ask me why I am doing this. Well I want to automatically pluck values from a directory full of spreadsheets (which all have the same format)the value of one cell from each.
I had tried to do it using the advice found here:
http://www.ashishmathur.com/extract-data-from-multiple-cells-of-closed-excel-files/
Unfortunately, I was only able to get the first step to work (create a list of filenames of the files in the source directory). The remaining steps are not possible because my employer does not allow downloading of add-ins for security reasons (it is a hospital).
So I thought the approach outlines above might work but I can't quite make it happen!
Thanks
Mike A
Use INDIRECT()
=INDIRECT("'" & B1 & "[" & B2 & "]" & B3)
As stated in the comments the ' would need to added to B3, so the input is Sheet1'!$C$5.
You may want to split the sheet name from the cell address then you could do:
=INDIRECT("'" & B1 & "[" & B2 & "]" & B3 & "'!" & B4)
Where B3 is only the sheet name and B4 the cell address.

Excel Indirect with Count

I have a workbook with different sheets for each month. I made another sheet where I put the months in A1 down.
I wanted to use Counta (for A:A in the months' sheets) and indirect together but I am getting the result "1" with my formula.
Please help:
=COUNTA(INDIRECT(SheetNames!A1&"!A:A"))
I would also eventually like to do the same for countif. If you can please explain what I missed that will help me.
Thanks!
Trying out your formula it works perfectly unless you've got a space in the worksheet name.
Try this formula:
=COUNTA(INDIRECT("'" & SheetNames!A1 & "'!A:A"))
When a sheet name contains a space then the sheet name must be enclosed within apostrophes. So =COUNTA('Sheet 4'!A:A) is a valid formula, while =COUNTA(Sheet 4!A:A) will not work and causes all kinds of problems.
The INDIRECT formula needs a valid reference as a string (rather than an actual reference) to calculate - so "'" & SheetNames!A1 & "'!A:A" returns the string 'Sheet 4'!A:A.

Excel cell referencing a variable sheet

So I have a tab for every month's worth of data, and then I have a summary that references the current month's sheet. Is there any way I can put "April 2015" (this would be the name of the sheet) in cell A1, and then have formulas like:
=COUNTIFS('(String in A1)'!$I$10:$I$149,B4,'(String in A1)'!$L10:$L149,"")
That way I'd only have to edit the 1 cell and I'd know all the references are correct whereas if one of the formulas don't get replaced, I'd be referring to a month behind on one random cell and likely never even know.
Seems like that should be very simple, but I can't seem to figure out how.
Be careful to preserve those single quotes:
=COUNTIFS(INDIRECT("'" & A1 & "'!$I$10:$I$149"),B4,INDIRECT("'" & A1 & "'!$L10:$L149"),"")

How to use a variable within a formula?

How can I merge different excel files (different in file name and values inside the sheet) with the same format in one excel file by a variable which is the name of the workbook ?
I can't change the name between the brackets for example ='[P2106.xlsm]management samenvatting'!B2 i would like the p2106 as a variable which refers to the cell that is the name of the workbook
I've tried cutting the formula in parts and then put it like ='[ & variable(cell) &xlsm]management samenvatting'!B2 , but this gives back the cell names nog the value that the formula should give. when I then copied the formula in word and back in excel the value from the formula appears.
I don't know what to do any more if there is someone who could help me thank you for that.
Single quotes are not seen as text qualifier by Excel, only double quotes are regarded as such.
For what you want to do, build a formula from pieces of text you will have to use the INDIRECT formula, with double quotes around all the text parts:
=INDIRECT("='[" & variable(cell) & ".xlsm]management samenvatting'!B2")
Off course variable(cell) needs to be further specified by yourself...
You were almost there.
Indeed as mehow commented, this only works with opened workbooks. If you want to do it with closed workbooks you can use VBA scripts.

Resources