Including tab name in formula from cell - excel

Similarly to this thread I have found Click here...
I am trying to create various formulae looking across tabs with the tab names kept in cells. My hyperlink function has been successful as:
=HYPERLINK("#'"&B2&"'!A1","Click Here")
Where B2 represents a 2-3 character tab name of a person's initials (e.g. AA in this example).
However if I try this method with other formulae I am returning a #VALUE! error. Can anyone help me with making this nested Index/Match function work dynamically from cell B1 rather than being fixed to the tab name "AA"?
=IF(OR(INDEX(AA!B:AH,MATCH(TODAY()-WEEKDAY(TODAY(),11)+1,AA!B:B,0),2)="",INDEX(AA!B:AH,MATCH(TODAY()-WEEKDAY(TODAY(),11)+1,AA!B:B,0),10)="",INDEX(AA!B:AH,MATCH(TODAY()-WEEKDAY(TODAY(),11)+1,AA!B:B,0),14)="",INDEX(AA!B:AH,MATCH(TODAY()-WEEKDAY(TODAY(),11)+1,AA!B:B,0),22)=""),"No","Yes")
Thanks in advance?
Dan

The hyperlink function accepts a constructed string to use as the link and interprets it as a range address just as it would a true url. A formula cannot accept a constructed string address as a worksheet range reference but the INDIRECT function converts constructed strings to a usable worksheet range reference.
INDEX(AA!B:AH,MATCH(TODAY()-WEEKDAY(TODAY(),11)+1,AA!B:B,0),2)
... becomes,
INDEX(indirect(text(B2, "'#'!\B\:\H")), MATCH(TODAY()-WEEKDAY(TODAY(), 11)+1, indirect(text(B2, "'#'!\B\:\B")), 0), 2)
With AA in B2, text(B2, "'#'!\B\:\H") becomes 'AA'!B:H. I find it easier to take care of the wrapping ' marks with a format mask.

Related

problems defining a sub range with INDEX formula

My understanding is that you can define a range using index. example I can set a defined name of MyList to
=index(A:A,3,1):index(A:A,5,1)
This would be the equivalent of saying A3:A5. I can then turn around and use index(MyList,1,1) and I would see the contents of A3. All this works for me.
So I was trying to define a range of sheet names. I used defined name sheetnames as:
=TRANSPOSE(GET.WORKBOOK(1,Structural!$J$3)&T(NOW()))
(I used transpose to get the list vertical)
when I use:
=INDEX(Sheetnames,3,1)
=INDEX(Sheetnames,6,1)
I get the name of my 3rd or 6th sheet in my workbook respectively. So that part is working. However when I try to define a range like I did for MyList using the following I get #value
=INDEX(INDEX(Sheetnames,3,1):INDEX(Sheetnames,6,1),1,1)
QUESTION:
Why is it not working?
As a test to get first sheetname I have also tried:
=OFFSET(Sheetnames,1,1,1,1)
This also gave the same error.
What I am ultimately trying to do is generate a pull down list through data validation of all sheet names except the sheets named "Index" and "Master".
As per Excel's help file on INDEX...
Reference form
Description
Returns the reference of the cell at the intersection of a particular
row and column. If the reference is made up of nonadjacent selections,
you can pick the selection to look in.
Syntax
INDEX(reference, row_num, [column_num], [area_num])
The INDEX function syntax has the following arguments.
Reference Required. A reference to one or more cell ranges
etc...
Therefore, in order to return a reference, you would need to reference a range of cells. SheetNames, however, doesn't refer to a range of cells. It refers to GET.WORKBOOK, which returns an array of values. In this case, it returns an array of sheet names.
So with the following formula...
=INDEX(INDEX(Sheetnames,3,1):INDEX(Sheetnames,6,1),1,1)
...it gets evaluated as follows (assuming the workbook is called Book1.xlsx and you have Sheet1, Sheet2, Sheet3, etc)...
--> some preliminary evaluations <---
=INDEX("[Book1.xlsx]Sheet3":"[Book1.xlsx]Sheet6",1,1)
=INDEX(#VALUE!,1,1)
=#VALUE!
You can evaluate the formula for yourself by selecting the cell containing the formula, and stepping through it using the Evaluate Formula button on the Ribbon (Formulas tab > Formula Auditing group).
You can also confirm that INDEX doesn't return a reference in this case by using the ISREF function. The following formula should return FALSE...
=ISREF(INDEX(Sheetnames,3,1))
Hope this helps!

Calling the same cell of different worksheets in EXCEL

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

Issue using Dynamic Named Ranges for Cascading Data Validation

I'm using two cells with Data Validation - the first cell (E9) simply creates a drop down menu based on the range A2:A6, and the second cell (E10) validation uses the source INDIRECT(E9), which will always refer to one of five different named ranges.
When I have the named ranges fixed, (i.e A2:A250), the second drop down works, but I really need the ranges to be dynamic, so far I've been creating named ranges with the following "source" formula:
=OFFSET(LookupLists!$B$2,0,0,COUNTA(LookupLists!$B:$B),1)
With the other ranges being the exact same only in columns C-F.
When I write out this formula it highlights the correct area on the screen, but the drop down button in cell E10 is completely unresponsive, when the drop down list should show the exact area that's being highlighted.
As a note, the lists themselves are created using an array formula and some VBA code to create a sorted unique list based on another part of the spreadsheet, so I've been unable to use tables to create the ranges as some other websites have suggested.
INDIRECT doesn't work with dynamic ranges. Credit to these guys for the solution:
http://chandoo.org/forum/threads/passing-a-named-range-to-a-formula-with-indirect.5854/#post-32423
First, insert a module into you sheet and paste in the UDF:
Option Explicit
Function RetrieveRangeForName(psRange As String) As String
RetrieveRangeForName = Range(psRange).Address
End Function
Then you will need a helper cell, since I don't think UDFs work in the Data Validation dialog. In E11, enter =RetrieveRangeForName(E9).
Then in the Data Validation, set to List, you can enter: =INDIRECT(E11)
The reason it doesn't work as discussed here is that INDIRECT expects a string that it can evaluate to give a reference. However your named range is already a reference. Logically, the only way to use it in INDIRECT is to convert it into a string first which you can do with a UDF:-
Function GetAddress(Name As String) As String
Dim rng As Range, addr As String
Set rng = Worksheets("Sheet1").Range(Name)
addr = rng.Address
GetAddress = addr
End Function
Then use this to define a range called NewRange:-
=INDIRECT(GetAddress(Sheet1!$E$9))
Finally this can be used in the validation for E10 (Named Range ListB is defined as in the question, ListA etc. correspondingly for columns A to E).

Converting a Text String that Links Two Sheets into a working formula

I am trying to convert a text string into a formula, but my text string is a bit unusual because it describes a link between two worksheets. Here is the starting formula:
+TEXT("+'X:\Deals\ONE-PAGERS\_One-pagers (vM)\["&TRIM(LEFT(SUBSTITUTE($B9," ",REPT(" ",30)),64))&" vM.xlsx]Metrics'!$D$8",1)
I created this formula to avoid having to manually link a large number of spreadsheets. It captures the first two words of a cell, and places that into a text string that would establish a link, if it were a formula. This way, I can simply enter a company name into cell B9, and this formula will produce a text string that describes the link I want. Here is the formula output:
+'X:\Deals\ONE-PAGERS\_One-pagers (vM)\[xxx vM.xlsx]Metrics'!$D$8
As you can see, if this were a formula, it would generate a link it would return the value in Cell D8 of the xxx worksheet. I have tried the evaluate workaround (seen below) as well as the indirect function and neither seems to be working. Let me know if this doesn't make sense and thanks so much in advance for your help!
Function EvalCell(RefCell As String)
Application.Volatile
EvalCell = Evaluate(RefCell)
End Function
Evaluate and INDIRECT would both require the source workbook to be open, but you could use ExecuteExcel4Macro:
Function EvalCell(RefCell As String)
Application.Volatile True
application.ExecuteExcel4Macro(application.convertformula(mid$(RefCell, 2), xlA1, xlr1c1))
End Function
I'd avoid using too many of these functions though!

Relative Referencing - Steps

I am trying to do relative referencing for a specific column (in Sheet "OA") where I need to retrieve the content of cells in a new sheet in steps of 110
e.g,
=OA!$AB217
=OA!$AB327
=OA!$AB437
Rather than manually code the formula in each cell, trying to drag the cells so the address could be dynamically generated.
On the above example, when I drag the cell, I am unable to get
=OA!$AB547
but getting
=OA!$AB220
I also tried to code it this way, "=OA!$AB($107+(n*$110))" where when the n values naturally incremented during the drag, I will get the right formula.
E.g
=OA!$AB($107+(1*$110)) => =OA!$AB217
=OA!$AB($107+(2*$110)) => =OA!$AB327
=OA!$AB($107+(3*$110)) => =OA!$AB437
=OA!$AB($107+(4*$110)) => =OA!$AB547
Unfortunately the format is not accepted by excel.
Could you please give me a hint what mistake I could have made ? My search on the internet have not been fruitful.
rgds
Saravanan K
You're looking for the "Indirect" function. Assemble a text string with the address of the cell you want, and call =indirect("string"). You can use the "&" operator to combine static strings with variables.
I've created a workbook with Sheet1 and OA
OA!A1:A1000 contain the numbers.
Sheet1!C1 contains 1
Sheet1!C2 contains 100
Sheet1!B1 contains =INDIRECT("OA!$A"&C1)
Sheet1!B2 contains =INDIRECT("OA!$A"&C2)

Resources