Cell reference to named area, with offset - reference

This is a question about OpenOffice spreadsheet, not Excel.
I have a named range which is a row of cells. (Say, the name in B4, the range C4:K4). I want to put a row of formulas underneath, where each formula references the cell within the named range at the same column. (The formula in C5 references C4, in D5 references D4, etc.).
Of course I could just use standard relative referencing, but I'd prefer to use the range naming.
How to do that?
I've played with COLUMN(), INDEX(), OFFSET(). I just get invalid reference errors.
Supplementary: there's something in Excel where you highlight a cell with relative references, and get it to recast the formulas using range-names. That might be called Names -> Apply IIRC. Is there something comparable in OpenOffice?

Provided your formulae are in columns C:K this is very simple, for example B5:B7 show the formulae in C5:C7 that have been copied across to ColumnK:
Why this is so is difficult to describe, but for Excel Doc.AElstein has attempted an explanation.

Related

How to use the INDIRECT function in Excel

I am using in Excel the following formula that works to get the value of a cell:
=INDEX(Sheet1!$1:$1048576,MATCH("Component 1",Sheet1!$A:$A,0)+MATCH("Component 2",Sheet2!$B:$B,0),2)
For a new application, the sheet and component names are dynamic, meaning that they are allowed to change and are not necessarily "Sheet1", "Sheet2", "Component 1" and "Component 2". Therefore I have tried to twist the above formula using the build-in INDIRECT function. I have tried two different ways to make it work:
1-
=INDEX(INDIRECT(A1&"!$1:$1048576"),INDIRECT("MATCH("&CHAR(34)&B1&CHAR(34)&","&A1&"!$A:$A,0)+MATCH("&CHAR(34)&B2&CHAR(34)&","&A2&"!$B:$B,0)"),2)
2-
=INDIRECT("INDEX("&A1&"!$1:$1048576,MATCH("&CHAR(34)&B1&CHAR(34)&","&A1&"!$A:$A,0)+MATCH("&CHAR(34)&B2&CHAR(34)&","&A2&"!$B:$B,0),2)")
where cells A1 and A2 values are the sheets' names and cells B1 and B2 receive the components' names.
Both approaches gives an error #Ref!. But I really cannot see what is wrong.
I would really appreciate any information for me to understand my mistakes and any suggestions to improve these formulas.
Thanks in advance!
Reason
You are using INDIRECT to compile parts of your formula, including the function names (e.g. "MATCH" in your "1-").
Instead, only use INDIRECT to build the actual references to ranges or cells (including qualifiers such as worksheet, workbook etc) inside those functions within your formula. Leave the rest of the formula outside the INDIRECT function.
So in your "1-", move "MATCH" back outside the "INDIRECT" function.
To get the "Component 1" to be volatile, just reference a cell containing that string in the normal way.
In your attempt "2-", you tried putting more of the formula inside the INDIRECT function, but it should have been less.
Answer
For example, you could try:
=INDEX(INDIRECT($A$1&"!$1:$1048576"),MATCH($B$1,INDIRECT($A$1&"!$A:$A"),0)+MATCH($B$2,INDIRECT($A$2&"!$B:$B"),0),2)
Even better
The difficulty is arising in part due to putting the sheet name in a range and the range reference hard coded in the formula.
You could consider putting "Sheet1!$1:$1048576" into A1 (for example), instead of just "Sheet1", and adjust formula accordingly. That way you can just edit A1, B1, B2 if the ranges change or grow, rather than editing the formula. Note that you would not be able to reuse A1 for the reference to "Sheet1!$A:$A", you would need a different cell to store that reference.
Also consider naming the cells A1, A2, B1 & B2, and referring to the named ranges in your lookup formula. That way if you move those cells around in certain ways it will be less prone to breaking your lookup formula.
Further thoughts
I presume you are across the performance tradeoffs of using volatile functions such as INDIRECT. If not, happy searching!

Auto Copy and Paste Cell Values not Formula to another Cell

I also need to get your help for the same issue. I need to copy the cell values and not the formulas automatically to the other Cell, "automatically" meaning, I don't need to click, use mouse, or any other means to do that, like once theres a value on that specific cell (which is derived from a formula), the value will automatically be copied and pasted in the other cell (without any intervention from my part) (Only the value is copied not the formula)
Note:
The cell should contain only the copied value and not the formula.
Scenario:
A1 Cell : has 250 value
B1 Cell : has a vlookup formula to search for the value of A1 cell (I need to use VLOOKUP as there's a lot of items in the list, and it is "Dynamic", the reason I cannot just use formula "=A1" to get the value directly)
C1 Cell : Needs to copy and paste only the plain value from B1 cell which is 250, not including the vlookup formula, it should be automatically copied without any intervention (Cannot use VBA code / Macro as it will be run in excel online)
Thanks!!
Just use abasic Excel formula.
Example:
The source data is in cell A1.
You want to copy the same value to cell B1.
In cell B1 write:
=A1
That is all.
Additionally, you need to configure correctly the strategy for calculating the formulas:
I managed to find a solution, sharing as might help someone in the future, just needed to use =value(A1), instead of just "=A1", when I did this, the chart can read the values as it is and not the formula behind it. Found another work around as well, by using the formula =A1+0, for some reason this works too. –
=value(A1) works perfectly , If that formula contains a % figure , simple We can multiply by 100 to get the correct value.

How to reference cell within '' worksheet title

I have the names of the tabs/worksheets (M-61,M-62,M-63W) at the top row (A1, B1, C1...etc)
I am trying to get a sum of several cells within the different sheets:
=SUM('M-60'!H21,'M-60'!H43,'M-60'!H86,'M-60'!H87,'M-60'!H97,'M-60'!H98)
However, right now I’m referring to the sheet itself, and have to apply the same formula to all the other sheets. This will require me to manually go and change all the sheet titles accordingly.
I was wondering if there is any way to reference the top row with the sheet titles within the formula so it automatically refers to the row text instead of me having to manually change the sheet title.
Edit
Now i got the reference to work, just wondering how would I do a sum of several cells in that tab
=INDIRECT("'"&$F1&"'!H87",TRUE)
Maybe:
=SUM(INDIRECT("'"&C1&"'!H21"),INDIRECT("'"&C1&"'!H43"),INDIRECT("'"&C1&"'!H86:H87"),INDIRECT("'"&C1&"'!H97:H98"))
(though there may well be a much smarter way).
You can use the INDIRECT function, which uses a string as an argument and converts it to a range. So
=M-60'!H21
is the same as
=INDIRECT("M-60'!H21")
or, if Sheet name is stored in, say, cell C1:
=INDIRECT(C1&"'!H21")
Your example has a SUM, though, which requires some adaptations. This your example:
=SUM('M-60'!H21,'M-60'!H43,'M-60'!H86,'M-60'!H87,'M-60'!H97,'M-60'!H98)
Since you are not using a range, you can convert that SUM into simple addition. Assuming Sheet name in cell C1
=INDIRECT("'"&C1&"'!H21")+INDIRECT("'"&C1&"'!H43")+INDIRECT("'"&C1&"'!H86")+INDIRECT("'"&C1&"'!H87")+INDIRECT("'"&C1&"'!H97")+INDIRECT("'"&C1&"'!H98")
This should solve your problem. More info here
By the way, if you were using a range, the OFFSET function with INDIRECT as an argument would work. But that's not necessary here.

INDEX(INDIRECT("DefinedName"),1)=#REF while INDEX(DefinedName,1) works

In an excel workbook, I'm referencing a defined name from another tab (to get dependent data validation). Accessing the defined name directly works, but accessing it through INDIRECT doesn't.
=INDEX(DefinedName,1) returns the first value of the range
=INDEX(INDIRECT("DefinedName"),1) returns #REF!
I have also tried
=INDEX(INDIRECT("SheetName!DefinedName"),1), but it also returns #REF!
Sample file can be downloaded here.
Thomas,
I hadn't come accross this before.
It appeas that INDIRECT and dynamic range names are incompatible. There is a useful reference here from Dicks blog
Not quite an answer, but it may have something to do with the fact that your named range is returning an array instead of a cell reference (in this case {"VALL";"GENADMIN";"HOSP";"CELLAR"}).
You can replicate the error by removing the named range and replacing it with its actual formula, and then F9'ing the formula:
=INDIRECT(OFFSET(Defaults!$C$1,1,0,COUNTA(Defaults!$C:$C)-1))
=INDIRECT({"VALL";"GENADMIN";"HOSP";"CELLAR"})
Since Excel is expecting some sort of reference to a sheet range, it is failing here since it can't resolve the array to anything specific (pressing F9 again yields ={#REF!;#REF!;#REF!;#REF!}).
The INDEX formula works because it can handle the array reference:
=INDEX(OFFSET(Defaults!$C$1,1,0,COUNTA(Defaults!$C:$C)-1),1)
=INDEX({"VALL";"GENADMIN";"HOSP";"CELLAR"},1)
={"VALL"}
Not an expert, but that's my best crack at it.
This absolutely will work. Maybe they were incompatible in 2012, but they certainly work in 2018. I imagine it would have also worked in 2012 if used correctly.
The INDIRECT function attempts to turn TEXT into a range reference. That TEXT must be a valid reference.
A named range is already a Range Reference. There is no need to get a reference from a reference. This is why the OP example works without using INDIRECT.
A more likely implementation would be if you had the value "DefinedName" from the OP, or any named range in a cell. Then point INDIRECT to that cell where it find plain ol' text. Then it turns that text into a range reference.
You can even use formulas in the INDIRECT to modify the reference. A common approach might be to have a Sheet name in a cell and then use INDIRECT to pull data from various sheets. This is primarily useful when you want to copy and paste formulas and have the sheet (or cell) reference dynamically adjust to a new target.
Setup
Start with a blank workbook which should contain three blank worksheets, (Sheet1, Sheet2, and Sheet3) If not, get to that point. Then enter the following basics:
Sheet 1
Cell A1, enter "Range Reference"
Cell A2, enter "SUM from Sheet"
Cell B1 enter "Sheet2!A1:A4" (Note there is no "=" This text is a range reference.)
Cell C1, enter "THIRD_SHEET" (This text is equivalent to a named range we'll create in a second.)
Then in Sheet2,
Cell A1, enter 1
Cell A2, enter 2
Cell A3, enter 3
Cell A4, enter 4
In Sheet3
Cells A1-A4 enter 100 through 400 respectively.
Then create a named range called "THIRD_SHEET" which refers to cells A1-A4 on Sheet3.
Try
In Sheet1:
Cell B2, enter the formula:
"=SUM(INDIRECT(B1))"
Copy that formula to Cell C2.
Results:
The INDIRECT uses the text in the column headings to point to a valid range reference. This is just illustration. You wouldn't likely use a mixture of named ranges and text ranges, and its not very clean to write out, "Sheet1!A1:A4" but you can use any of the standard formula to arrive at a textual reference.
Try
Change the formula in B2:
"=SUM(INDIRECT("Sheet"&COLUMN()))&"!A1:A4"))"
Now copy that to cell C2.
Results
Well, are the same. The SUM from cells A1:A4 is being returned from Sheets 2 and 3 respectively. This time, however, the column headers are not being used, and the range reference is being assembled in the INDIRECT call itself using the string join "&" operator and the COLUMN number.
Named ranges can be used in the same way. What's important to understand is that anything inside the INDIRECT parenthesis needs to first be resolved to a vaild TEXT range reference.
I hope that helps!

Authoritative Excel range syntax reference

Sorry if this has been asked before but I can't find it. I am looking for an authoritative description of all valid strings that can be used as a reference, e.g., "A1:C5", "$A:$A", $A2" etc etc. That seems a pretty basic thing yet I've wasted hours trying to locate it. All I can find is a swamp of "helpful" examples but no reference.
This seems like a fun exercise. I'm going to list as many as I can, and hopefully other people could point out ones that I've forgotten/missed/didn't know about.
A sort-of guide to what you're asking for, and a source for anyone looking for additional documentaion: http://www.excelfunctions.net/Excel-Reference-Styles.html
I'm going to start with 5 broad categories - A1, R1C1, Table, Formulas, and VBA references. I'm going to ignore other programs that can interact with Excel for the moment (Although I might add in Python if that's officially added in)
All examples will be using A1 reference style, since they're more intuitive for an inexperienced user.
A1 Reference type:
A1 style tells us the coordinates of a given cell. The alphanumeric portion tells us which column we're in, while the numeric portion tells us which row we're in.
Cell References:
A1 - The basic cell reference. References the cell A1, and as you drag formulas through columns and rows, it'll change. For example, if your formula is in C1, and you move it to D2, it'll now reference B2.
Good use: Comparing two sheets to each other. ='Sheet1'!A1='Sheet2'!A1 will compare the data in sheet 1 to sheet 2, and give a true/false if they match or not. Formula can easily be slid sideways and up/down for additional comparisons.
$A1 - This locks the column. As you drag formulas, the row will change, but the column won't. Useful if you always want to reference the same column in a formula. For example, if your formula is in C1, and you move it to D2, it'll now reference $A2.
Useful example: Formulas in helper columns. A1 = $C1*2 will neatly slide down without any issues, and if you move it over to the B column, it'll continue to reference C.
A$1 - This locks the row. As you drag formulas, the column will change, but the row won't. Useful if you always want to reference the same row in a formula. For example, if your formula is in C1, and you move it to D2, it'll now reference B$1.
$A$1 - This locks the cell reference. No matter how you drag the formulas around, it'll continue to reference cell A1. For example, if your formula is in C1, and you move it to D2, it'll now reference $A$1.
Useful example: Constant multiplier for all numbers.
To summarize, A1 References are broken out as follows:
Alphanumeric portion - What column we're in
Numeric portion - What row we're in
$ - Locking the portion immediately following
Range References:
Due to the sheer number of combinations of range references, I'm sicking to the most common. Mixing and matching types of cell references with types of range references will get every combination.
A1:B2 - References the grid of cells with A1 being at the top-left, and B2 being at the bottom-right. Both parts of the formula will slide when moved. It's generally recommended not to have unlocked references in formulas applied over multiple cells, since the reference range will also move. For example, if you have =Sum(A1:B2) in C1, and you move it to D2, it will transform to =Sum(B2:C3).
Unlocked range references most often cause problems in vlookup formulas, where the reference range ends up changing as people slide the formula down.
$A$1:$B$2 - References the grid of cells with A1 being at the top-left, and B2 being at the bottom-right. This range reference won't change, even when moved. For example, if you have =Sum($A$1:$B$2) in C1, and you move it to D2, it will transform to =Sum($A$1:$B$2)
$A$1:A2 - This locks the first cell, but leaves the second part of the reference flexible. This is very useful when you want to see "Everything that's happened so far"- For example, if you're numbering a list, when combined with =countifs ("What instance of occurrence is this one?") For example, if you have =Sum($A$1:A2) in C1, and you move it to D2, it will transform to =Sum($A$1:B3)
Similar effects can be used with $A$1:B1 going horizontally.
A:A - This gives the entire column A. Since this is unlocked, it'll slide. Useful for grabbing everything in a given column. For example, if you have =Sum(A:A) in C1, and you move it to D2, it will transform to =Sum(B:B)
$A:A - This gives the entire column A. This will expand as you go across to grab more columns. I can't think of an immediate practical use for it. For example, if you have =Sum($A:A) in C1, and you move it to D2, it will transform to =Sum($A:B)
$A:$A - This gives the entire column A. This is locked to column A, even if you move the formulas around. For example, if you have =Sum($A:$A) in C1, and you move it to D2, it will stay as =Sum($A:$A)
Slightly lesser known are rows:
1:1 - The entire first row. Unlocked. For example, if you have =Sum(1:1) in C2, and you move it to D3, it will transform to =Sum(2:2)
$1:1 - The entire first row. Partially locked. For example, if you have =Sum($1:1) in C2, and you move it to D3, it will transform to =Sum($1:2)
$1:$1 - The entire first row. Completely locked. For example, if you have =Sum($1:$1) in C2, and you move it to D3, it will stay as =Sum($1:$1)
R1C1 References
R1C1 is more of a reference style as opposed to a coordinate style. This can be extremely useful, since your formulas in all of your cells look exactly the same, and makes entering sliding formulas in VBA significantly easier.
R1C2 is broken down as such:
R - Rows
1 - Row 1 OR
[1] - We're 1 row down from our current cell
C - Columns
1 - column 1 OR
[1] - We're 1 column over from our current cell
In other words, if you don't have brackets, you're referencing the cell or column in question. If you do have brackets, you have a relative reference.
Cell References:
R3C7 is an absolute reference - 3rd row, 7th column. This would be the same as saying $G$3 in A1 style, as detailed above.
R[3]C7 is partially absolute, partially relative reference. This is asking for "Give me the cell 3 rows down from the current cell, in column 7" (Which is column G) If I have this in cell A1, I'd be referencing cell G4. If I move it to cell B2, I'd be referencing cell G5.
R[2]C[-2] is a full relative reference. You can also reference earlier columns or rows, as indicated by the - sign. If I had this formula in cell C1, it would be referencing cell A3. If I move the formula to D2, I would now be referencing cell B4.
Range references:
Table References
Tables make referencing other cells and ranges easy and intuitive. They're broken out as follows:
TableName[ColumnName]
Formula References
VBA References
VBA Conversion from Letter to Column
Something that's come up a few times is changing column numbers to column letters. I found this very helpful piece of code (somewhere on Stack Overflow, I don't currently have the link handy) to convert column numbers to column letters for ease of use in VBA.
Function Col_Letter(lngCol As Long) As String
'Converts a number (usually generated from an application.match function) to a letter. For example 1 turns into A, 5 turns into E, etc.
Dim vArr
vArr = Split(Cells(1, lngCol).Address(True, False), "$")
Col_Letter = vArr(0)
End Function
Under Construction*
I don't know if there is a list of formats, because there really are only 2: A1 format and R1C1 format.
You're not actually specifying a range format when you use A1:C3 because the : is actually the range operator.
The variants of $A$1, $A1, A$1 are just that - variants, identifying that when copying the reference the coordinate before the $ should not change, but that otherwise the coordinate may change relative to the copy.
R1C1 is more complex, because it allows relativity. R3C2 is an absolute reference to Row 3, Column 2 (B3 in A1 notation), while the use of braces [] in an R1C1 reference indicates that it is relative to the current cell R[-2]C[1] from cell R3C2 would give R1C3 (C1).
Nearly forgot. There can also be a reference to cells in another worksheet. 'Sheet2'!IV256
I use
(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)
as a regexp for identifying cell references in the A1 format
The problem is that there are a variety of operators (Range, Intersect, implicit intersect etc ), functions (INDEX, OFFSET, CHOOSE, INDIRECT + user-defined functions), Defined Names and structured Table references etc that can all be de-referenced to provide a valid range reference. So to do a complete job means parsing arbitrary Excel formulae.
And it also varies by Excel version.
If all you want to do is work with standard explicit range references the usual trick is to convert the string to R1C1 notation and work with that. The syntax for R1C1 references is reasonably well described in Excel documentation.
There is also a BNF description of Excel formulae available somewhere but I have mislaid the reference.
"it's used for identifying cell references that might need modification when inserting a new row or column in a worksheet"
If the rows/columns are inserted with Excel live (as opposed to hacking into the workbook using another application), any references will update to the new address automatically.

Resources