I'm trying to create a reference to an array of cells in column A, but instead of a reference of the form A1:A100 I seek to make a reference of the form A[value at cell B1]:A[value at cell B2]. Does Excel support this method of referencing cells?
Much gratitude.
To create dynamic cell addresses in formulas you can use:
=indirect("A" & B1 & ":A" & B2)
This also works for addressing cells on another worksheet.
Also note that any part of a cells address can be a variable. (i.e. the sheetname, the column or the row)
Indirect is especially useful in that it protects the address even if the worksheet referenced is deleted, typically producing a #Ref!
Related
I've been given an old calendar workbook.
It has direct cell references to other sheets to fill the spaces in the calendar.
I have been tasked to change these to show TBD when nothing is entered in the secondary sheet(s).
I've got the formula figured out: =IF(REF=" ", "TBD", REF), so a cell which references secondary sheet R, cell A1 would look like =IF(R!$A$1=" ", "TBD", R!$A$1).
However, there are dozens of these cells. Pasting over them overwrites their original cell values, so I was wondering if there was a way to paste in the formula while maintaining not the cell value in the copied cell, but in the destination cell.
Thanks!
So i'm working on a spreadsheet where i need to lookup a value from a tab of which the name is defined in a cell, in this case D7. Using this method i can dynamically search my workbook tabs and select the correct tab and cell reference.
The problem i'm having is that the cell i'm retrieving will not change when i drag down the formula.
=INDIRECT("'"&$D7&"'!S2")
D7 = dynamic tab name
S2 = cell to retrieve... here is where I'm having the problem, this is a value i want to change when i drag down.
Please can someone help here?
You can use the row of the cell with the formula to calculate the row of the referenced cell:
=INDIRECT("'"&$D1&"'!A" & ROW())
note: the above assumes the formula is in the same row as the cell you are referencing (row 2 in your example)
I am trying to create a hyperlink in Excel that references a cell on my worksheet, to get the sheet name.
Here is the working formula, with a static value.
=HYPERLINK("[\\xxxfs01\xxxxxxxx\IT\Monthly Reporting\Data\Computers Report for xxxDMZWSUS01.xls]Sheet1!A1","CLICK HERE")
When I use INDIRECT to reference a dynamic value, the cell just shows a value of #VALUE!
Here is what I have tried.
=HYPERLINK(INDIRECT("""&[\\xxxfs01\STS-Defence\IT\Monthly Reporting\Data\Computers Report for xxxDMZWSUS01.xls]"&[#Sheet]&"!A1&""","CLICK HERE"))
=HYPERLINK(INDIRECT(CHAR(34)&"[\\xxxfs01\STS-Defence\IT\Monthly Reporting\Data\Computers Report for xxxDMZWSUS01.xls]"&"Sheet1"&"!A1"&CHAR(34),"CLICK HERE"))
Can anyone help with the correct syntax?
You don't need INDIRECT to put together a Hyperlink location (INDIRECT is specifically intended to allow you to change the cell being reference in a formula, and that's not what I think you're trying to do). I'm listing steps below, because I think it might be a tiny bit confusing what you are trying to do, so this gives you a chance to see if I understood your problem correctly.
You are in Worksheet1.xlsx, Sheet1
In cell B2 of Sheet1, you want to enter the name of a worksheet from a different file: Computers Report for xxxDMZWSUS01.xls
In cell B3 of Sheet1, you have a hyperlink to go to cell A1 of the worksheet named in cell B2
The formula in B3 should be:
=HYPERLINK("[\\xxxfs01\xxxxxxxx\IT\Monthly Reporting\Data\Computers Report for xxxDMZWSUS01.xls]"&B2&"!A1","CLICK HERE")
INDIRECT Worksheet Function
Returns the reference specified by a text string. References are immediately evaluated to display their contents. Use INDIRECT when you want to change the reference to a cell within a formula without changing the formula itself.
An example of using INDIRECT and HYPERLINK is:
=IF(TRIM(A2)="","",IF(ISERROR(INDIRECT("'" & A2 & "'!$A$1")),"missing",
HYPERLINK("#" & "'" & A2 & "'!$A$1",INDIRECT("'" & A2 & "'!$B$2")) ))
Reference is http://dmcritchie.mvps.org/excel/indirect.htm
When I write a formula to compare data in different workbooks, the formulas looks very cluttered since each time I reference a value in a different workbook, the entire name of the workbook appears in the formula. Is there a way to assign an alias to the workbook name so the formula is more readable?
The simplest way would be to store the path to the workbook in bits(separate cells)
using variables(Text in Cells) in book1 type:
A1 = book2
A2 = Sheet1
A3 = A1
Now go to any empty cell in book1 and type the formula
=INDIRECT("'["&A1&"]"&A2&"'!"&A3)
The Indirect() pulls values from the Cells and replaces them creating a string which in the end is equal to =[Book2.xlsm]Sheet1!A1
So, instead of hard-coding the names of other opened workbooks, sheets, or ranges you can use values you entered in any other cell in your book1.
Now if you were to compare the value against some other cell from the other book, replace the A3 with the actual value or change the A3 from A1 to some other cell
There is a downside to the =INDIRECT() function. It does NOT work with closed workbooks.
You can use a named range to refer to a different workbook.
Just add a named range as normal and enter:
=[WorkbookName]Sheetname!Range
eg
=[Book1]Sheet1!$A$1:$A$10
You can then use this in formulas that take ranges, to refer to an individual value can be trickier and you'd need to use lookup/index.
In excel 2007, I have a formula in a cell like the following:
=COUNTIFS('2008-10-31'!$C:$C;">="&'$A7)
Now I want to make the name of the sheet ('2008-10-31') be dependent on the value of some cell (say A1). Something like:
=COUNTIFS(A1!$C:$C;">="&'$A7) // error
Is there is way to do this? Or do I have to write a VBA-Macro for it?
INDIRECT does what you want. Note that if the sheet name has any spaces, you need to put single quotes round it, ie
=COUNTIFS(INDIRECT("'" & A1 & "'!$C:$C"); ">=" & $A7)
You are looking for the INDIRECT worksheet function:
=INDIRECT("SHEET2!A1")
=COUNTIFS(INDIRECT(A1 & "!$C:$C"); ">=" & $A7)
The function turns a string into a real cell reference.