I am trying to create a dynamic range using Excel functions that will sum values between the two named ranges.
This is similar to creating a table in 2010, whereby you can sum all additions to the table.
My issue is that I do not want to create a table. I would simply like to specify a start and ending point and create the range from there.
I tried separating two named ranges by a colon, i.e. rng1:rng2, but this does't work the same way as using two absolute cell references like A1:C16. Instead, it selects the two ranges individually, not a range bounded by the two.
Is there any way to accomplish this?
Currenlty, I use dynamic ranges using the OFFSET and COUNTA functions, but these will only work if you are interested in an entire row/column or a specific range.
On the contrary to Addikt's last comment summing 2 defined ranges does not sum only their upper left most value.
Answer is here:
Name rng_1 and refer it to H13:H16
place the number 1 in all cells in that range
Name rng_2 and refer it to I13:I14
place the number 2 in all cells in that range
In cell K13 type = sum(rng_1,rng_2). Answer will be 8, not 3.
Completely wild guess based on a lack of clarity in your question, but let's say you have a series of numbers in column A. You could "dynamically" sum numbers in row 1 through n as follows:
=SUM(A1:INDIRECT(B1))
Where cell B1 contains a value like "A10" (this would sum cells A1:A10).
Change the cell named in b1, and your sum formula will update accordingly. You could also specify the full range in B1, i.e. if cell B1 contains "A1:A10":
=SUM(INDIRECT(B1))
Related
I'm searching for a way to link the range of an Excel table to a specific number.
Let's say I have a table that has a range of A1:B10. I want to make the number '10' dynamic and link it to a number that is calculated from another sheet. Let's say cell F1 contains that number and the value is '20'.
Is it possible to make a dynamic range so the table range changes to: A1:B(F1). Then my table would adapt automatically and this has to work in my file.
I prefer a formula instead of a macro in VBA, because I normally don't work with VBA.
An alternative is to use a dynamic named range which is what we used to do before tables. The range, enclosed by marching ants below, is defined as follows:
=OFFSET(Sheet3!$A$1,0,0,Sheet3!$F$1,5)
The top left cell is A1. It is as many rows deep as the number in F1 and 5 columns wide (which could also be made dynamic).
Yes, INDIRECT is your way to make any formula dynamic / dependent on other cell values.
Say you want to sum range A2:C2. But the value 2 for C is located in Cell G2.
=SUM(INDIRECT("A2"&":C"&G2))
this is equal to write =SUM(A2:C2) in my example below.
If you set G2 to 3 it would calculate A2:C3 for this =SUM(INDIRECT("A2"&":C"&G2)).
If you mean Excel table, I guess the answer is no with formula, probably with VBA.
I have the following formula:
=IF(MAX(C2:F2)>0,COUNTIF(C2:F2,">1")/COUNT(C2:F2),0)
This formula is located in the second column of a structured table, and goes through the rest of the columns in the table to the right. The formula basically tells how many instances satisfy a certain criteria and puts it in a fraction over the total number of instances. So if the criteria is met 2 times and there were 3 instances I get 2/3 as the output.
I have been researching for an hour now and I can't figure it out. Is there a way to get the cell range in the formula to auto-expand when a new column is added?
You should take advantage of Structured Referencing and Index to get the parts of the table you need
=IFERROR( COUNTIF(
INDEX(YourTableName[#],1,(COLUMN([#FormulaColumn])-COLUMN(YourTableName[#])+2)):
INDEX(YourTableName[#],1,COLUMNS(YourTableName[#])),
">1") /
COUNT(
INDEX(YourTableName[#],1,(COLUMN([#FormulaColumn])-COLUMN(YourTableName[#])+2)):
INDEX(YourTableName[#],1,COLUMNS(YourTableName[#])))
,0)
This will count number of cell to the right of the Formula Column that are >1 and divide that by the count of cells to the right of the Formula Column that are not blank.
The key point here is COLUMNS(YourTableName[#]). This will increase automatically as you add columns
Note: if you want to include blanks in the divisor count, the formula can be adjusted to suit
Just change YourTableName and FormulaColumn to suit your data
From what I can make of the data, the problem can be solved by creating a named range that refers to:
=OFFSET($C$2,0,0,1, COLUMNS(myTable))
The change to the formula is:
=IF(MAX(myRange)>0,COUNTIF(myRange,">1")/COUNT(myRANGE),0)
Where myTABLE is the name of your table and
Where myRANGE is the name of the new named range
How it works:
The named range counts the number of columns in the table and updates whenever one is added it removed. Offset anchors to the left side of the table and extends to the right by the number of columns in the table. The formula drops the cell reference in favor of the named range for improved legibility. It can be copied dragged pasted and moved all over the place and still point to the correct range. With adequate scope, you could put it anywhere in the workbook without issue.
Note: My biggest pet peeve about this method comes when copying the sheet to a a new workbook. Named ranges are so awesome that a workbook scoped range will point to the original workbook even after it has been copied to a new workbook. Sometimes that's a good thing, but us mostly it's a nuisance.
I believe an alternative answer will compliment the first answer because there are innumerable occasions where one may want a dynamic range and simultaneously not want a table.
And that's the clue, for more information you can search for dynamic range. Or more specifically: dynamic named range.
To answer your question:
Yes, it is possible and it's also very handy. For example, the print area can expand and contract with your data and it's very easy to interact with because you work with by name rather than address. And when using VBA, I find it's generally easier to work there named range than a table, that is, unless the table is bound to a variable, in that case they would be equal in my eye. There is just something a fundamentally loathe about typing listobject("table name").listcolum("table colum name").datapropertyrange I almost have a visceral reaction when I have to type it.
The gist of it creating a dynamic named range is simple. Open the name editor, name a range, and use offset() and counta() to define your range. Counting non-empty cells pulls double duty. it is the trigger to recalculate the range and it provides an index that can be used with offset to change the range area.
Here is one example: =OFFSET($A$1,0,0,COUNTA($A:$A),1)
It is very straight forward. With one exception, print range.
For whatever reason, print range doesn't behave the same way and doesn't update like a normal named range. To make it dynamic you create a named range like you normally would. This will be your print range so make it count. Then make your print range refer to that named range. That's all there is to it. The first named range points to the area you want to print and the print at range points to that named range.
My problem:
I have the below tables:
In my second table (tbl_analysis), I need to create a formula in the Sum column that will sum the salary of a certain person over a certain period. When the period changes, the formula needs to be recalculated.
My try:
I started off by using the formula:
=SUM(my_range)
By the range can't be hard-coded, so I decided to find the cell address of the corresponding month as you can see in the range D12:E15
Formula in the cell D12:
=CELL("address",INDEX($A$2:$M$8,MATCH(A12,$A$2:$A$8,0),MATCH(B12,$A$2:$M$2,0)))
So when I tried to insert the above formula inside of the SUM formula like this:
=SUM(CELL("address",INDEX($A$2:$M$8,MATCH(A12,$A$2:$A$8,0),MATCH(B12,$A$2:$M$2,0)))
: CELL("address",INDEX($A$2:$M$8,MATCH(A12,$A$2:$A$8,0),MATCH(C12,$A$2:$M$2,0))))
And then Excel is referecing the cell address itself and not the address inside of the formula.
Skip the Addresses and use this based on the months:
=SUM(INDEX(A:M,MATCH(A12,A:A,0),MATCH(B12,$2:$2,0)):INDEX(A:M,MATCH(A12,A:A,0),MATCH(C12,$2:$2,0)))
Scott Craner has the right solution for this scenario and it makes more sense here. However if you would absolutely need to get cell reference from a cell you would be able to do it using the following function:
INDIRECT(cell)
Usually this isn't necessary but it can be handy when you want to break up a long formula where you would need to find a row number for example.
INDIRECT("A" & B2)
Where B2 has the row number for a dynamic range or specific moving target row.
INDIRECT function documentation
I am trying to create a SUMIF function that dynamically adds up values in a specific column of a named range in my Excel sheet.
It is very easy to do this when there is no named range :
The formula picks out all the cells that contain "London" in their name and sums up the expenses related to London.
What I am trying to do is to use a named range called TripsData (A2:B5) and tell the SUMIF function to sum the entries in the column 2 of this range that meet the criterion of having London in their name.
How can I make this work without needing to create a second named range for column 2 and simply by telling Excel to look within the specified column of this named range? Index/Match only return one value so that doesn't work when there are several cells with London in their name.
Thanks for your help!
Use INDEX to refer to a specific column in the named range (it can refer to a whole column), like this
=SUMIF(TripsData,"*London*",INDEX(TripsData,,2))
You can do that without any named ranges at all, if you turn your data into an Excel Table object. Select any cell in the range or the whole range and click Insert > Table or hit Ctrl-T.
There will be a dialog that asks if your table has headers. Yours does. Now you can reference the table and its columns by their inherent names and build your formula like this:
=SUMIF(Table1[Expense],"*London*",Table1[Cost])
You can rename the table, of course, even after the formula is in place. When you click a cell in the table, there will be a new ribbon for commands that relate to tables only. It's a very powerful tool.
Any formulas, formatting etc. that apply to a whole table column will automatically carry over into new table rows. The table column reference will adjust automatically, too, of course, so you don't have to mess with dynamic range names or re-define what a named range applies to.
Note: the formula uses structured referencing instead of cell addresses. This option can be turned off by clicking File > Options > Formulas > tick or untick "Use table names in formulas"
You can use Chris' idea of Index(Table1,,Col#) with the named range "Table1" (without creating an Excel table Object if you don't want to for some reason) and STILL avoid the problem Applez mentions in the comment below Chris' idea. Applez warns that using a constant for a column number reference is dangerous if you later insert another column before that column in the named range. You will find that Excel does NOT auto increment the constant, so your formula breaks.
Applez is right..... so DON'T use a constant, use a column number "reference" instead of a constant. For example....
=SUMIF(TripsData,"*London*",INDEX(TripsData,,Column(B1)))
If you later insert a column between A and B, Excel WILL auto increment the reference Column(B1) to Column(C1). Just don't delete B1 or Row 1 or you will get a REF error. I usually use the the header/tile "cell" (in whatever row that is in) for that table column within the Column reference (as it is highly unlikely I will ever delete the header/title cell of column of a table unless I delete the entire column). In this particular example as it turn out, B1 "IS" the the title/header cell for that column in the data table. So that is what I used for the example.
Awesome formula, just in case anyone needs to use a similar approach to FILTER a range. I used this approach
pmGendHC is the range I wanted to filter (I expect a spilled range with my data) I needed a colum (column number 13) to be different than 0
=FILTER(pmGendHC,INDEX(pmGendHC,,13)<>0)
been looking for quite a while now, due lack of distinctive terminology couldn't find any solution, so maybe the experts out here can help.
So I got this table of 300+ collumns that are populated like this
row 1 Header/Name.
row 2 Range formula ment to be in the "Refers to" input area when a "New Name" for a range is created.
row 3/22 The information used in the range formula.
To use the range formula's in a data validation on another sheet I need to Name these ranges. If I manually enter a "New Name" I can copy the range formula from row 2 into the "refers to" input area, only with 300 columns that would be a long day of labor. That's when I found out about the CRTL+SHIFT+F3 combo which makes it possible to create a lot of named ranges at once based on a header/name and selection. Unfortunately this uses the location of selection as the source and in my case it should be the formula inside the locations's cell which would have to be the source...
So is there a way to use the "Create Names From Selection" tool that uses a formula inside a cell as the source instead of the location?
here's an image to help describe the problem
You should be able to solve this problem with 1 named range for every validation (plus 2 additional to make the formula less complicated).
The first named range (all_headers) should be defined as:
=OFFSET('C'!$A$1,0,0,1,COUNTA('C'!$1:$1))
It returns a range with the headers (product names or codes) from the C sheet. We assume that the first column is A and there are no empty columns between them.
Next we need to choose the right column. Here it gets a little tricky. In the row where you want to validate colors, you need to have exactly the same product name or code that is used in the C sheet headers. If this information is in cell A2, you should:
select the cell in the same row and in the column where the color validation is supposed to be (for example B2)
define new named range col_header with the following formula:
=INDEX(all_headers,1,MATCH(A2,all_headers,0))
The above dynamic named range is relative, that's why selecting the proper cell before defining it is very important.
The last step is to define named range val_list with reference to the list of colors from the chosen column:
=OFFSET(col_header,2,0,COUNTA(OFFSET(col_header,2,0,50,1)),1)
You mentioned that the second row does not contain data, that's why there is 2 parameter twice in the formula. If you remove it, use 1 instead. 50 is the maximum number of colors - you can adjust it.
Now you can use val_list for validation in any cell. It should give you the right list if the cell on the left contains a valid product name/code from the C sheet header.