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.
Related
I'm hoping someone can help me make better use of the INDIRECT formula.
I have a list of sheet names in a table and an INDIRECT formula that uses that list to return a value in a specified cell - the list of sheet names is just an easier way for me to drag the formula down the table and read the appropriate cells without having to manually link each sheet.
=INDIRECT("'"&A2&"'!"&"K10")
This works fine for single cells as the range ref is simply stated as the text in the formula (K10), the problem arises when I need to start referring to a range such as K10:K15 and summing the values.
The range K10:K15 will inevitably have new rows added or deleted on the relative tab and as INDIRECT is using text as the reference it means the range doesn't automatically adjust - this is as I understand it one of the 'benefits' of INDIRECT but in this case is actually holding me back.
Also worth noting that the range (K10:K15) may move as rows are added/deleted above this, as this range is part of a larger table.
In simplistic terms I want to achieve the same result as a standard reference to a range on another sheet, e.g. =sum(sheet1!K10:K15) (as this will adjust when rows are added/deleted) but I just want to be able to dictate which sheet is referred to via a list I have in a table on a summary sheet.
How do I either write INDIRECT so the range adjusts when new rows are added/deleted or is there a different formula I should be using that achieves this?
Any advice greatly appreciated :)
=INDIRECT("'"&A2&"'!K"& MATCH(TRUE,INDIRECT("'"&A2&"'!K:K")<>"",0)&":K"&MAX((INDIRECT("'"&A2&"'!K:K")<>"")*(ROW(INDIRECT("'"&A2&"'!K:K")))))
This indirectly references the rows from the first non empty cell up to the last non empty cell in given sheet in column K. Not sure if you need to enter with ctrl + shift + enter (not in the app version).
Note: If the range contains empty cells in between the first and last non empty cell it will be included as value 0
Or in office 365 use the following:
=FILTER(INDIRECT("'"&A2&"'!K:K"),INDIRECT("'"&A2&"'!K:K")<>"")
Suppose I have a simple spreadsheet with 3 rows of data that I want to rank in separate columns. The example I will use is simple, but my actual dataset is 12k + rows. In this simple example, I want to use the RANK formula from Excel to do this. To rank the values in column Police, I'll use the formula =RANK(B2, B2:B11, 1), with B2:B11 being the range.
As I mentioned, my actual dataset has thousands of rows and many more columns to compare. Even in this example, I want a simple way to copy the formula to all of the other _RANK column cells. If I simply copy the cell to the other cells, +1 gets added to the cell value. This is what I want to happen, EXCEPT for the ending cell of the range.
As you can see above, this is incorrect. The formula gets set to =RANK(B11,B11:B20,1) for cell E11, when what I want is =RANK(B11,B11:B11,1). How can I easily copy this formula across multiple cells so that it is has the correct formula?
Placing $ before the cell references makes it static. Try changing your formula to Rank(B11, B$2:B$20,1). Coping this formula will only change those references which are not proceeded with $.
I have been building up an excel sheet to interrogate a data set and produce a set of metrics. I'm aiming to make the process as expandable as possible.
In the links are pictures of a simple mock up data set to illustrate what I'm trying to achieve, it contains a metrics sheet where I want to display the information and the data set sheet:
and the
The aim is to have the highlighted cell (D6) display the number of items in "Sheet2" that meet the criteria of Item Status "Open".
I have managed this at first with the formula:
COUNTIFS(Sheet2!C:C,"Open")
and then to make it more expandable using:
COUNTIFS(INDIRECT(" ' "&D4&" ' !C:C "),"=" &C8)
This means I can use a cell (D4) to reference the sheet I want to look in and a cell (C8) to reference the criteria I want to search for. This works well until I need to look for blanks in the data set, at which point it counts all the blanks in the column specified (see cell D8 in metrics sheet).
So I was wondering if there would be a neat way to specify the column range to look in, eg C1:C100, by using cells to reference the range similar to using the cells to reference sheet and criteria. I can use the below formula but it still requires the sheet name to be written in the formula rater than referenced out to a cell.
COUNTIF((Sheet2!C1:INDIRECT(CONCATENATE("Sheet2!C", B2))),""&C8)
When I apply this to the data sets I'm looking at I will need to consider multiple sheets where the data sets will contain the same criteria (located in the same column across all sheets) but the data set will vary in length. This is why I'd like to keep the cell formula referencing the variables out to specific cells in the metrics sheet so that if I add in a new data set or criteria that I want to look at I don't have to re-type a load of formula but just copy it across.
UPDATE
Following the answer from JvdV I have been able to remove all the variables from the formula into cells in the metrics sheet (useful for what I'm doing and may be of interest to others). It essentially uses the 'INDIRECT' and 'CONCAT' functions to build the string needed, colour coded picture
Here is something you can try to suit your needs:
The formula I used in F1 would translate to:
=COUNTBLANK(INDIRECT(G1&"C1:C"&COUNTA(INDIRECT(G1&"A:A"))))
Cell G1 is just a list like:
If you don't want to have all used rows but use the range specified in your cell B2 then I guess it would look like:
=COUNTBLANK(INDIRECT(G1&"C1:C"&B2))
Beware; using INDIRECT() causes your formula to be volatile!
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)
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))