I have an Excel Sheet called "master", one called "all-names" and one called "table-20-01".
In the master sheet I want to write a formula, that gets a sheetname out of a cell in the "all-names" sheet and that name is for example "table-20-01". I want to use that name to reference a cell in that sheet. According to my research I'm supposed to use the INDIRECT Function for that (for example Increment Worksheet References
So I thought that I could do something like this:
=INDIRECT("'" & "'all-names'!A1" & "'!$A$1")
'all-names'!A1 ==> "table-20-01"
'table-20-01'!$A$1 ==> The value I'm looking for
I use this because I want to create formulas that automatically increment sheet references. And since the sheets are not numbered as simply as sheet1, sheet2, sheet3, but table-20-01, table-20-02, ..., table-20-12, table-21-01, I have the names stored in the sheet "all-names".
Unfortunately I am getting a REF error. Anyone?
Related
I may going up the wrong tree with this.
I have the following formula, that will replace the * with the range of sheets in the workbook, and SUM the values in cell B2 on each of the sheets:
=(SUM('*'!B2)/J2)/100
This works fine, however the formula doesn't retain the '*', it replaces it with the actual range, eg:
=(SUM('Period 1:Period 4'!B2)/J2)/100
So, is it possible to either:
Retain the '*' so that the formula doesn't update, and therefore remains dynamic should I add a new tab.
Add a reference into the reference. The first sheet will always be 'Period 1', however the end sheet will change from month to month, and will be 'Period x', where x is the value in cell J2. Is it possible to reference J2 within =(SUM('Period 1:Period 5'!B2)/J2)/100? =(SUM('Period 1:Period [J2]'!B2)/J2)/100 or something similar?
The only way I know to do this is to create a 'sheet sandwich' with a 'Start' and 'End' sheet then the range is =SUM('Start:End'!B2). New sheets obviously have to be inserted between these to be included.
Note:not my solution, credit belongs to SUM across multiple sheets with variable sheet name question.
I have a drop down list (with name of sheets) and based on that value, let's say that I select the Sheet4 as in the image, I want to bring to another sheet the value of that selection, let's say on the cell B8.
I know that this works:
=IF(B1="Sheet1", Sheet1!B8, IF(B1="Sheet2", Sheet2!B8, Sheet3!B8))
That's for just 3 sheets but is there a nicer or more efficient way to do this?
This is in general how all the sheets look like:
Use INDIRECT to construct a valid worksheet and cell reference from text-that-looks-like-a-worksheet-and-cell-reference 1
The indirect takes a string and turns it into a valid reference.
=INDIRECT("'" & B1 & "'!B8")
So in the case above it would create a string "'Sheet4!B8". Then the Indirect will turn it into a valid cell reference.
As Jeeped also pointed out in the comments The B8 reference since it is literal text it will not change if the formula is copied or dragged to another cell.
The B1 which is a cell reference and is relative will change as it is copied or dragged to different cells.
1 as per #Jeeped comment
I want to use the value of a cell in a reference formula.
For example:
I have a sheet with name '815108' which has all the data I need.
Now in the sheet1(new sheet), in A1 I type in ='815108'!A3 which gets the data from A3 in the sheet '815108'.
But the question I have -
In my new sheet 815108 is a defined attribute (For example: SO = 815108 is defined in cell F5.)
Instead of using '815108'!A3 I want to use the location in the current sheet. I tried ='=F5'!A3 which doesn't work. Any help is appreciated.
Thank you.
This is one of the few times that the INDIRECT should be used:
=INDIRECT("'" & F5 & "'!A3")
INDIRECT is a volatile function that translates a string into a viable reference.
Being volatile it will re-calculate every time Excel re-calculates regardless if the data to which it refers has changed or not.
I'm looking automatically to calculate the average of 40 values that come from a .csv file, which I have managed to do.
My problem is I would like it to take the values from any separate workbook based on the cell value from the original workbook, so this can automatically calculate the average from any one of a number of available spreadsheets.
This is the formula I'm using currently:
=Sample1.csv!C1
And this is the what I tried, which obviously doesn't work:
=B4.csv!C1
With B4 containing the word Sample1 or any other Sample Number.
The formula you can use to refer to a cell on another sheet
=INDIRECT(B1 & "!C1")
Where B1 has the sheet name and you get the value of cell C1 from it.
It can be used to get data from another workbook , so long as the other workbook is open.
eg
=INDIRECT("[Book1.xlsx]a.csv!$A$1")
=INDIRECT("[" & B1 & "]!$A$1")
Where B1 has the name of the workbook
In practise you might use:
=INDIRECT(B1 & "!" & C1)
Where C1 contains (ie stores as a value!) the address of the cell you want to reference. Thsi is useful as it allows you to copy the formulas such that the addresses change.
It is better to use the CELL function as follows which uses CELL to get the Address of A1 as text eg "$A$1". This means the formula can easily be copied and pasted into the cells you want it to be in.
=INDIRECT(B1 & "!" & CELL("address",A1)
Enjoy.
You can use the Indirect() function to have Excel interpret a text string as a cell reference, and this string can be constructed with the text values from one (or more) cells.
So in your example use:
=INDIRECT(B4 & "!C1")
which retrieves the value "Sample1" from B4 and concatenates this with the second part of the string to give "Sample1!C1" that Indirect() then uses as an address & retrieves the value from there.
Lets say
sheet3.name = "d"
Is there a way I could put in a cell on sheet2 the formula =sum(sheet3!b:b) where sheet3 is being substituted with the actual sheet3 name?
I can only get =sum('d'!b:b) to work so far.
I could use VBA for this probably but I'm curious how to do this in a cell so I don't have to run a macro each time.
If you can use a UDF User Defined Function that will return the sheet name
Function SHEETNAME(number As Long) As String
SHEETNAME = Sheets(number).Name
End Function
then a formula like
=SUM(INDIRECT(SHEETNAME(3) &"!B:B"))
will return the sum from column B on sheet 3.
SHEETNAME(number) returns the sheet name of the number which is index.
So Sheet(1) returns Sheet1, etc
Use below formula anywhere in the sheet to get the sheet name - the sheet must have a filename for this to work:
=REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")
You can either reference that cell using Indirect:
=SUM(Indirect("'"&A1&"'!B:B"))
or, if you don't want to have a second cell, you can combine the two formulas into one:
=SUM(INDIRECT("'"&REPLACE(CELL("filename"),1,FIND("]",CELL("filename")),"")&"'!B:B"))
For anyone not concerned with the order of the sheets, the post by Biff here on mrexcel.com works well.
In Excel 2013, go to the Formulas tab in the ribbon and make a defined name:
Name: SheetNames
Refers to: =GET.WORKBOOK(1)&T(NOW())
Then use a formula like this example:
=INDIRECT("'"&INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),A3)&"'!A1")
where A3 refers to the index number in a cell in the current sheet, and A1 refers to the location of the value to be retrieved from the other sheet. I.e., in the current sheet, if A3 = 2, then the formula will point to cell A1 in the second sheet of the workbook. I just use a column of index numbers in my current sheet, then drag this formula down and it fills in values from all of my other sheets.
You will need to save as a macro-enabled file (.xlsm).
I'm not sure if this is a good idea but it's the first one I could think of.
I would add additional function to your VBA project which will return actual name of your Sheet3:
Function Sheet3Name()
Sheet3Name = Sheet3.Name
End Function
Next, when you create sum formula of column B:B in Excel cell you need to do it in this way:
=SUM(INDIRECT(Sheet3Name()&"!A:A"))