I have the sheet, say "StackOverflow", and a value in cell A1, "Hello", that I want in my sheet "Test" at a specific cell.
I know that I could type ='StackOverflow'!A1 to get the cell value. The thing is that I do not always want to use the sheet "Stackoverflow" and instead want it to be like
=B1&!A1
where B1 holds a value that corresponds to a worksheet in my workbook.
How would you go about this?
You can use the INDIRECT function :
=INDIRECT("Stackoverflow!A1")
or
=INDIRECT(B1&"!A1")
=INDIRECT(B1 & "!" & A1)
Note that the above allows you to place any cell reference in A1.
If you want it to always refer to A1, then use
=INDIRECT(B1 & "!A1")
=INDIRECT(B1&"!"&A1) would do this.
Related
I have a value in the cell A1 that can be "PERSON, REGISTRATION,CONTRACT"
Then I have to add in the cell A2, an hyperlink to another spreadsheet:
If the value of cell A1 is PERSON go to spreadsheet2
If the value of cell A1 is REGISTRATION go to spreadsheet3
If thevalue of cell A1 isCONTRACT go to spreadsheet4
How can I do this please ?
Thank You -
Something like this:
=HYPERLINK("#'" & CHOOSE(MATCH(A3,{"person";"registration";"contract"},0),
"Sheet2","Sheet3","Sheet4" ) & "'!A1", "Go")
Edit: some explanation
MATCH(A3,{"person";"registration";"contract"},0) -finds the position of the value in A3 in the array of possible values.
Given that position, use CHOOSE() to pick the correct one from the three possible worksheet names to use in the hyperlink address.
The rest is just stringing all of that together to create the link formula.
Try this one:
=HYPERLINK("#"& LOOKUP(A1;{"contract";"person";"registration"};{"sheet4!";"sheet2!";"sheet3!"}) &"$a$1";"LINK to " & LOOKUP(A1;{"contract";"person";"registration"};{"sheet4!";"sheet2!";"sheet3!"}))
It is important the lookup_value must be in alphabetical order and you should be sort the lookup_vector accordingly.
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 have an excel file with multiple sheets. I reference data in sheet 2 like:
=sheet1!A1,
I would like to use a variable to change the function based on a value entered in cell x on sheet2 . I tried:
=sheet1!"x"1
to try and change all formulas based on entering a value for x. This didn't work because excel thought I was referencing something in sheet 1. I can't do this with VB due to security restrictions.
Use the indirect() function:
=INDIRECT("'Sheet1'!" & A1 & "1")
Where A1 is the cell in which you find "x".
The best way to do this is by using =INDIRECT("'Sheet1'!" & A1 & "1")
EDIT: Dang I'm too slow, Scott is like lightning.
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.
In an excel cell, I've placed a simple formula
=C4
The cell typically displays the value of cell C4, but instead I want to see the linked cell ID instead, which in this case is "C4".
Is there a formula to show me this? like:
=SHOWCELL(C4)
The reason I need this instead of simply typing the value of "C4" into the cell, is so Excel will maintain the link to the correct cell even if rows are inserted/deleted, AND show me which cell is linked.
You should be able to use the Cell function.
In Excel, the Cell function can be used to retrieve information about a cell. This can include contents, formatting, size, etc.
=Cell("address", C4)
This displays $C$4.
When inserting a row before C4, it is changed to $C$5.
In case you do not want the $ signs, one way would be the Substitute function:
=Substitute( Cell("address", C4), "$", "" )
You can create your own User Defined Function to achieve this. I call it "CellReference".
Usage:
=CellReference(B6)
displays "B6"
To use it, launch VBA, insert a module, and then copy the below into the module:
Function CellReference(cell As range) As String
CellReference = cell.Address(0, 0, xlA1)
End Function