I know how to make a named range in Excel.
I have a spreadsheet, with various columns going across as parameters, and then finally a formula in the last cell. This is repeated many times in each row, with each row having a different set of data, and the formula updated to reference the correct row index.
However, the formula looks like (three rows worth):
=G2*(10*D2 + 20*E2 + 5*F2)
=G3*(10*D3 + 20*E3 + 5*F3)
=G4*(10*D4 + 20*E4 + 5*F4)
I would like to use named ranges, but I can't find a way to do something like
=Count * (10*var1 + 20*var2 + 5*var3)
where count, var1, var2, and var3 automatically update to be the particular column of the current row. I can create a named range for every cell, but that isn't helpful. I can name range the column, but then I can't find a way to put an offset into the formula.
Also the whole point of this is readability, so if it ends up being some nasty complex formula function call, that probably doesn't help too much.
Simple, at least when using Excel 2010:
name your column: select full column, enter name
use column name in formula; Excel will combine the referenced column with the current row to access a single cell.
Using the example from Alex P:
select column D by clicking the column header containing the "D", enter name "input1" into name field, and press Enter.
repeat for columns E to F, using "input2" and "input3", respectively.
Do not define additional names defining names "input1" [...] as in example above!
use the formula as given in the example above
Attention:
Using named columns this way, you cannot access any other row as the one your formula is in!
At least I'm not aware of the possibility to express something like <ColName>(row+1)...
I would suggest creating a Table. Select your range A1:H4, then go to the Tables widget > New > Insert Table with Headers (on Mac). This will mark A2:H4 as body of the table, and A1:H4 as header.
From that, you get:
Whatever you put into the header column will define the name for this column automatically, e.g. Count, Radius, Density, Height
You can then write your formula using =[#Count]*(10*[#Radius] + 20*[#Density] + 5*[#Height])
When you change the formula in cell H2, Excel will automatically "copy down" this formula to all cells in column H. So no more accidental inconsistencies in the formulas.
When you need to add another row, simply click the last cell (in our example H4) and hit Tab. Excel adds another row, and also makes sure to "copy down" your formula into the new row.
If you need a total row, add it with the Total Row checkbox in the Tables widget. Excel adds a total row automatically. If you click any cell in the total row, you can change the "total formula" with the "▼▲" button, for example to calculate the Average instead of the Sum of the column.
If you have a long table and scroll down so that the header is not visible anymore, Excel automatically displays the column header instead of the column names (Count instead of G for example).
I can really recommend the video You Suck at Excel with Joel Spolsky which explains all of that.
Suppose I have the following numbers set up in columns D to F in rows 2 to 4:
D E F G
2 10 15 20
3 1 2 3
4 20 30 40
Now suppose I want the value in column D to be known as input1, column E to be input2, and column F to input3:
In Insert > Name > Define...
input1 RefersTo =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1)
input2 RefersTo =OFFSET(Sheet1!$E$2,0,0,COUNT(Sheet1!$E:$E),1)
input3 RefersTo =OFFSET(Sheet1!$F$2,0,0,COUNT(Sheet1!$F:$F),1)
Now if I write my formula in column G as follows I should get correct answers:
G2 =(10*input1+20*input2+30*input3) // 1000
G3 =(10*input1+20*input2+30*input3) // 140
G5 =(10*input1+20*input2+30*input3) // 2000
I haven't fully reviewed the previous answers, but I think this is closer to what #Jason Coyne the OP was looking for. So, I hope I get a lot of up votes. ;-)
Excel allows your formula to refer to tables and columns by name if you "Format as Table". Here is an article titled Using structured references with Excel tables that goes into detail.
FWIW, it looks like this feature has been available since Excel 2007.
Here is a screenshot of an example:
You should be able to see the formula in E2 is =[#Count] * (10*[#Var1] + 20*[#Var2] + 5*[#Var3]) which is pretty close to what #jason-coyne wanted to type.
I don't like that you are forced to pick a style (or define a new one if you don't see a style you like). The good news is you can reformat the cells all you wish without undoing the "tableness".
It insists on turning on auto-filter. But, auto filter is easy to turn off (see the Filter Button checkbox under the Table Tools Design menu).
It also insists on having non-empty, unique values in the header row (Which kinda makes sense). If you delete a header cell, or insert a column, Excel will invent a new, unique name and stuff it in for you. D'oh!
If you want a column to not have a header, you can enter an apostrophe (') followed by one or more blanks. Remember header values need to be unique, so keep adding blanks if you want more than one column without a header.
If you would like to download the sample workbook in the screenshot, here is a link: https://filebin.ca/3vfaSDn4NLEA/SampleWorkbook.xlsx
Adding to Alex P's answer:
Instead of using =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1) as the formula for input1, I recommend to use =Sheet1!$D$2:INDEX(Sheet1!$D:$D,COUNT(Sheet1"$D:$D))
It produces the same result, but it is non-volatile, i.e., only recalculate when a predecessor cell changes. This is much better in a larger model!
If you're using VBA, then you can select the whole column and name it, say MyCol, in the name box (upper left input box). The in your code you can refer to a cell in the column MyCol (line 12) using the following code:
Cells(12, Range("MyCol").Column)
You might be able to use the row() function. This returns the current row that you are in. So depending on the layout of the spreadsheet you can use it like this:
=offset(NamedColumn1, row()-1)
The -1 is because you are saying how many rows to move down from row 1 which if you are in row 1 you want to be 0.
Use the Excel feature called named references.
To name a cell or range of cells
select that cell or range of cells
Enter its name in the Name Box ( its left of the formula widget and has the cell name )
You can't use names that conflict with cell names, like k0.
The named cells can be used if formulas. E.g.,
=pi*radius*radius
I'd like to propose a slight variation of the cell reference made by Dror. This will work as well:
Range("MyCol").Rows(12)
Related
How do I find either the cell address or preferably the row and column of the value 119, or any other number in the table below?
The table does not contain row or column titles, only the numbers as shown.
I am looking for a worksheet solution (formula) and not a VBA solution.
An Array Formula
This is an array formula and it has to be entered with control shift enter i.e. hold control shift and then press enter.
=MAX(IF(A1:J34=119,ROW(A1:J34)-ROW(A1)+1))
Remarks:
The value is searched by column i.e. A1, A2, ... B1, B2 ... i.e. if you had another 119 in cell D1 the result would still be 2, and if you had a 119 in cell c1 then the result would be
1.
For a column version just replace ROW with COLUMN:
=MAX(IF(A1:J34=119,COLUMN(A1:J34)-COLUMN(A1)+1))
Well, clunky and you can expand it, but it does work:
Row is separate to column but you could put them together in one cell, does depend on how you want to use the results, but you did not specify that so I have done this...
You could use a choose() function or a lookup table with vlookup() to change the column result to a letter...
Please try:
=MOD((K1-50),34)+1&" | "&1+(INT((K1-50)/34))
where K1 is your selected value.
Returns R | C. (Data in A1:J34 is not required.)
Below is a general purpose answer based on VBasic2008's answer.
I modified the formulas to utilize defined names so that the cell references do not have to be hard coded in the formulas. This way both the data table and row / column formulas can be relocated to anywhere on the spreadsheet. It works for both numerical AND text based data.
I also included the =ADDRESS() function to return the absolute reference of the look up value.
For illustration purposes, a step by step example for Data Set 1 is shown replacing the hard coded cell references with defined names.
The Data Set 2 section is the simplified version just using one defined for each the row and column look up value.
You can download an example spreadsheet here: Look_Up_a_Value_in_a_Table.xls
Thanks to all of you: Solar Mike, VBasic2008, and pnuts
Click on the image to enlarge.
I'm working with a fairly large data set, I have a list of names which appear more than once in column B and in column C i have the team they are part of.
In column C which displays there team name most the data is there but I do have a few 1000 where no team name is not present. Is excel smart enough to go for example Jamie#soso is part of design because it case in "B36" "C36" and then assign design to the missing field?
Here is an example of the data with the missing team names
And here is a view with what im looking for end result wise.
If I need to explain this better please let me know and thank you in advance.
On the assumption that there are no ambiguous entries, you could do the following:
if the order of the data is important, add an index column and insert ascending numbers for all rows of data (hint: enter the first two values manually, then select the first two cells and double click the fill handle to fill all the way down to the end of the data)
Sort the data by name and then by team as secondary sort
select column B
hit F5 to open the Go To dialog
click Special button
tick the option Blanks and click OK
now all blank cells in column B are selected
without changing the selection start typing a = sign, then hit the up arrow on your keyboard.
hold down the Ctrl key on your keyboard and hit Enter
now each previously blank cell in column B will have a formula that references the cell above.
copy column B
paste special on column B and paste values to get rid of the formulas
use the index column created in the first step to return to the original sort order
If you want this exercise to be repeatable, you could also use Power Query. Load the data into the Power Query editor, sort by name (ascending) and team (descending), select the Team column and click Transform > Fill > Fill down. The screenshot shows the result
To do without VBA, add a helper column in column C and insert this array formula:
{=INDEX($B$1:$B$17,MATCH(A1 & "?*",$A$1:$A$17&$B$1:$B$17,0))}
To create an array formula, type in the formula without the curly brackets, then press CTRL+SHFT+ENTER. Excel will add the curly brackets.
When you have your column C results, you can copy and paste values to overwrite column B if you want to get rid of your helper column.
This formula looks for rows with a value in A that matches the current row (i.e. same name), and any value in B that isn't blank; "?*" ensures at least one character. The match look up value is therefore A & non-blank B, and the array it's looking in is both A column range and B column range. The INDEX part provides the value from column B if it exists.
Names with no matching column B already completed will give you #N/A so you can manually enter those.
I want to put 58+2 instead of 60 in Microsoft Excel cells. But, when I do that the cell is not counted for summation or other functions. How do I put 58+2 in a cell and get results?
If I put =58+2 inside the cell, due to AUTOSUM it automatically turns to 60
enter image description here
You can solve this with a couple of helper columns (which you can then hide from view). I'll give you two options/examples
In the example titled 'From helper columns to display' In Columns C & D I keep the raw values of the marks and the bonus. Then in Column A I use the
formula
=C3&"+"&D3
To give my result. In column F I can then calculate totals etc. based on the columns C and D.
In the example titled 'From display to helper columnns' this assumes you already have the data stored as xx+x. In column C I use the formula
=VALUE(LEFT(A7, FIND("+",A7)-1))
And column D
=VALUE(RIGHT(A7, LEN(A7)-FIND("+",A7)))
To get the actual values. I can then again use these columns to calculate my totals etc.
The columns C & D can be hidden for visual purposes. Both of these scenarios will achieve the same result it just depends what the format of your data is currently in as to which one you would use
For any cell you want to calculate instead of hard-code, add an equals sign at the beginning
=58+2
will be evaluated by Excel to be a function rather than text and will evaluate it.
I have an excel document with two sheets, data and edu-plan. The sheet data has the following information:
The sheet edu-plan looks like this:
My question is: how do i create an excel formula that checks if the target group on the specific row in edu-plan! has the course name in question on the same row as the target group in sheet data!, i.e. if Sales and Sales course is on the same row in the sheet data!?
In reality, the data sheet as a couple of hundred rows and will change over time, so i am trying to develop a formula that i can apply easily on all rows/columns in edu-plan!.
The desired result in edu-plan would look like this:
A pivot table might be a good way to go.
If you would like to do it by formula, then you can just use a COUNTIFS
=IF(COUNTIFS(data!$A$2:$A$10,$A2,data!$B$2:$B$10,B$1),"X","")
A possible way to solve your issue with an array formula:
Write in B2 of sheet edu-plan
{=IFERROR(IF(MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)>0,"x",""),"")}
Since it is an array formula, you need to hit shift + ctr + enter.
Here is the formula broken down:
MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)
checks whether the combination of row header and column header is in the data table. MATCH returns the index of the found combination. Since we are not interested in the location, we only ask IF(MATCH > 0, "x", "") to write an "x" if a match was found. If MATCH finds nothing, it returns an error, which is why we add an IFERROR(VALUE, "") around the construct.
I have a sheet setup that calculates totals. Easy enough if the data is already there but not if adding new data. So what I would like to be able to do is to not specify a specific end cell for the sum formula but let it update as more columns are added.
How can I do this with =SUM(m4:m?)
Suppose you need totals for data in M4:M10.
To make just open-ended range, you can make lower limit "too far": =SUM(M4:M100000).
Alternatively you can make it as =SUM(M:M) - SUM(M1:M3)
But this is not applicable when you need to have totals value just below the set of values. In this case you have 2 ways.
Using Excel embedded features
The formula will look like his: =SUM(M4:M10). If you insert a new row between M4 and M10 (for instance, select row 5, right-click, insert row), you formula will be automatically adjusted to =SUM(M4:M10).
The problem may happen if you want to insert a new value above the first row (select row 4, right-click, insert row) or below the last row (select row 11, right-click, insert row). In these cases totals formula will not be adjusted.
Possible workarounds:
For the "above first row" issue, I prefer to make some empty row above and hide it. In our case I would hide row 3 and make totals formula look like =SUM(M3:M10), so, when you insert a new row above the first row, in fact you insert a row to the middle of the table, and totals formula will be adjusted.
For the "below last row" - leave empty row below; but in this case you cannot hide it; just make it different color and make some remark like "new values shall be inserted ABOVE this line".
INDEX()
Interesting trick is using INDEX() function, which returns a reference to a cell in the array. For our case, the array can be the whole M row and, the index - row number.
For the "above first row" issue make totals formula like this =SUM(INDEX(M:M;4):M10). So, calculation will always start at row 4, even if some lines will be added/deleted.
"below last row". Suppose you have your "totals cell" in M13 and you want to have totals for all value between M4 and the "totals cell". The formula may look like =SUM(M4:INDEX(M:M;ROW(M13))) or, considering "above first row" case: =SUM(INDEX(M:M;4):INDEX(M:M;ROW(M13)))
Hope this helps
Sum(m4:m?) insinuates that you are looking to add more rows as opposed to adding column data.
If you want to auto sum a row data you can use something like:
=SUM(OFFSET(A1;0;0;COUNT(A:A);1))
However this assumes that the data is contiguous in each cell and also empties are not allowed for 0 because it gets the count wrong.
However: You could also define a table for the data range. If you add data to columns/rows that are in that data range, they will be included in the adjusted formula automatically - very nice indeed.
Select your data range, then Select Insert:Table. This will give your table a name like Table1.
Your sum function would now be adjusted to look something like:
=SUM(Table1)
Now, as you add to the range, the table resizes, and your function just works.
The beauty of using a table, is that if you add data to the row/column immediately after the table it resizes and includes that range. This is hard to do without a table. You can also change the format of the table, or make the format colours invisible but you're probably better off with some format to show the data area of the table to the user.
You can compute the last row containing a number using this formula:
=LOOKUP(2,1/ISNUMBER($J:$J),ROW($J:$J))
This formula would not have a problem if you had text or blanks in the range.
You could then define that formula as a Defined Name
and use the formula:
=SUM(OFFSET(J4,0,0,LastRow-3))
to Sum the range. Note the -3 at the end to compensate for the first cell being in row 4.
Another option would be to just set your range to a fixed range that you can guarantee will be larger than any range you might actually use:
=SUM(J4:J1000)
You can use a counta to find the max row number. Then pushing that into an indirect will give you the range you need.
=SUM(INDIRECT("A1:A" & COUNTA(A1:A1000000);TRUE))
Assumptions:
Data are on column A
Data start from first row
There are no blanks rows