I have two worksheets; Sheet1 contains different building names (repetition) and Sheet2 contains a list of the building names. I will like to count the number of building in sheet1 and show them in sheet2.
Currently, I'm using workbook function COUNTIF. How can i do it if there's a new building added in sheet1? (VBA or workbook function is fine)
You could create a dynamic named range in sheet 1 (for the list of buildings), and then refer to the named range in your countif function in sheet2.
For more details on how dynamic named ranges work, have a look at this:-
http://www.ozgrid.com/Excel/DynamicRanges.htm
Another alternative would be to use the whole column that contains the building names, as your countif function will only return a value for cells that contain the criteria specified in the function. It might look something like this:-
=countif(Sheet1!A:A,"building a") <--this would search for all cells containing 'building a' in column A of Sheet 1
As you use either dynamic range or A:A range on CounIF() it works only as long as you do not have any blank cells within the range. Please know that. In such cases you are better off with a pivot table and pointing to pivot table's total cells accordingly.
Or if you still prefer to use CountIf() in blank cells case, you may apply conditional formatting to fill the blanks with some text/string. Don't forget conditional formatting contributes to slowing down your sheet performance. Or you could wrap CountIf() with an IF condition.
Related
I have an Excel document that I need to have a totals sheet which takes in a specific cell over multiple sheets. It also needs to be expandable so I can just add the sheet name to a row or something and it will add it into the formula and the total.
Just a row like this or something similar which could be used to add more sheets in future.
To give you an example currently, I am using a simple SUM function but it's not easily expandable:
=SUM('Sheet1'!A6,'Sheet2'!A6,'Sheet3'!A6)
I have had a look at INDIRECT but I can't find a way of having it expand to the length of an array eg. something like this:
=SUM(INDIRECT(H3:H8,"!A6"))
Would return all the values of A6 across each sheet named in H3:H8 evaluating like:
=SUM(INDIRECT(H3,"!A6"),INDIRECT(H4,"!A6"),INDIRECT(H5,"!A6")...)
If anyone has any ideas of what I can use to achieve this, it would be very helpful!
If you want a dynamic list of sheets for your sum formula, you may
Put the names of the sheets across which you would like to sum your cell(s) on a separate range of cells organized as a column range:
Sheet1
Sheet2
...
Convert the cells with the names of sheets into a table (select your range, then on the main menu panel select "Insert - Table").
Name the created table list (i.e. "List_of_Sheets")
To sum use the formula:
=SUMPRODUCT(SUM(INDIRECT("'"&List_of_Sheets&"'!A6")))
You may change the names of sheets in your table or add the new ones at the end of the table
Try this,
SUM(Sheet1:Sheet3!A6)
You can add a Sheet named „Start“ and one named „End“.
Place all sheets you want to sum between the both. So you can use
SUM(Start:End!A6)
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)
Here is a screenshot of my data:
I want to search B4:B40 and C4:C40 and find all cells that are blank for both specified ranges. If blank in both ranges, return the text in the corresponding row in column A. Ideally, the output could be combined and it could list something like 8:00-2:00.
here is what i have so far:
=INDEX('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!B4:B40, MATCH("",'C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!B4:B40,0),'C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!B2)
Am I on the right path?
The formula you want is:
=IFERROR(INDEX($A$18:$A$40,AGGREGATE(15,6,(ROW($A$18:$A$40)-ROW($A$18)+1)/(($B$18:$B$40="")*($C$18:$C$40="")),ROW(1:1))),"")
I will let you put in the workbook and sheet references. They are only needed on the Ranges. Do not put them on the Range references in the the ROW() functions. They are only there to return a number and it does not matter the sheet to which they reference. Just make sure that the ranges themselves match.
The concatenation with the workbook references would make the formula long and unwieldy. To do that VBA would be the best route.
Edit:
Got bored and decide to put in your workbook and worksheet references:
=IFERROR(INDEX('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!$A$4:$A$40,AGGREGATE(15,6,(ROW($A$4:$A$40)-ROW($A$4)+1)/(('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!$B$4:$B$40="")*('C:\Path\to\other\worksheet\[Blank Schedule Grid.xlsx]Susan'!$C$4:$C$40="")),ROW(1:1))),"")
Do you want all the values in a single cell or in a new column?
=IF(AND(ISBLANK(B18), ISBLANK(C18)), A18, "")
Assuming your data starts in A18 (as per the screenshot), you can put this in cell D18 and copy all the way down.
I've got a large Excel workbook with multiple worksheets and copious amounts of data. Every third sheet is an amalgam of the previous two sets. I've set up the following formula to pull the data from each worksheet, add it together, and present it in the third worksheet:
=SUM(VLOOKUP($A7,'worksheet 1'!$A:$F,2,FALSE)+VLOOKUP($A7,'worksheet 2'!$A:$F,2,FALSE))
This works as expected, unless the column A value is in one of the source worksheets but not the other. Then, I get the #N/A error with "Value not available."
What I want to do is make it so that, if the column A value is not present in the first worksheet, excel ignores that VLOOKUP request and simply pulls in the data from the second worksheet (and vice-versa for a value in the #2 but not #1).
If VLOOKUP isn't the appropriate tool to use, I can change it. I had an example sheet that I used to build this query, and that's how they put it together.
I am not an Excel expert and I've never used Access, so I'm learning as I go. Any assistance is appreciated!
Since you are using numbers, you could actually use multiple sumif statements.
I would suggest something like:
=SUM(SUMIF('worksheet 1'!$A:$A,$A7,'worksheet 1'!$B:$B), SUMIF('worksheet 2'!$A:$A,$A7,'worksheet 2'!$B:$B))
SUMIF is faster, won't look in the entire range, and if it does not find the value in A7, it will simply return 0.
I hope this helps.
UPDATE
Simple example. Say we have 2 sheets with a total column and we would like to get the value of that total cell:
you could sum 2 VLOOKUP forumale, or you could use SUMIF as follows:
=SUM(SUMIF(Sheet1!$A:$A,$A$7,Sheet1!$B:$B),SUMIF(Sheet2!$A:$A,$A$7,Sheet2!$B:$B))
The above is simply saying: Look for the value in cell A7 in the range $A:$A in sheet1 and return what's in the same row in the range $B:$B, and do the same in sheet2, then sum them both.
Note that SUMIF will actually sum all the resutls in a range, so if you have 2 totals in Sheet1!$A:$A then it will sum them both up. In a way this is the opposite of what VLOOKUP will do: it will stop once the first row containing the value is found. SUMIF won't stop.
The desired result in the example above is 208 and that's what you shall get.