问题
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
回答1:
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!
来源:https://stackoverflow.com/questions/55261929/excel-counting-no-of-items-in-a-different-sheet-between-a-certain-range-matchi