问题
I have a workbook with multiple sheets. One is a MASTER sheet with all of the information with various columns of various pieces of info. There are other sheets that are counting various cells throughout the MASTER sheet, and I am already using COUNTIFS
to accomplish this, but what I would like to do is create queries that will create sums based off the color of the text from one column, given that they meet the requirement of having certain info in a different column.
For example:
This is a list of various personnel. Each person belongs to a different section. They also complete different courses of training at different times (represented by BLACK font), while some are pending certain courses of training (RED), and some are currently in training (BLUE)
What I would like to do is on the tracking sheet, have a 3 cells track each color in a given column, based on the section they are in.
While I am familiar with COUNTIFS
, and I can also set a VB module to create a function to count the cells on the same sheet, I just can't seem to make it work across different sheets.
回答1:
With two sheets the same (for the example) except Sheet1 without the block showing the count:

where the formula in F2 shown is:
=COUNTIF(B:B,D2)+COUNTIF(Sheet1!B:B,D2)
Courtesy Siddharth Rout.
Note you would need to save this as .xlsm to preserve the defined name.
回答2:
The nice method used by pnuts, Siddarth, Siddarth, relies on two resources:
A method for detecting the text color,
=GET.CELL(...)
.A method for referencing the appropriate cells,
OFFSET(INDIRECT("RC",FALSE),0,-1)
.
Regarding #2, there is another option:
OFFSET(INDIRECT(ADDRESS(ROW(),COLUMN())),0,-1)
PS: It gives exactly the same result, and I personally find this use of INDIRECT
easier to understand (the other use comes from the legacy XL4, and it is not documented in current versions). I even use similar formulas, sometimes combined with ADDRESS
, directly in worksheet cells.
PS2: This interesting link suggests appending +NOW()*0
to the =GET.CELL(...)
formula to ensure automatic recalculation. I found in Excel 2007 it is not needed, for any of the two options for #2 (did I miss something?). It shows also other nice tricks for referring to ranges.
来源:https://stackoverflow.com/questions/20530468/counting-cells-of-particular-color-text-in-various-columns-in-different-sheets-i