Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

excel - COUNTIFS and OFFSET

I have a dynamic table that starts at Row A5 (so I'm adding rows to the table constantly and the countif formula is located a couple of rows beneath the table in column C). 5 is the header row. Rows A1-A4 are commented. Data starts at A6. Having a little trouble with the height argument in my formula. I want to count number of rows with a value starting at A6 to the end of the table). Here's my current formula.

COUNTIF(OFFSET(A6,0,0,ROWS(A:A)-ROW(A6),1)"<>")

This works, however the height argument (ROWS(A:A)-ROW(A6)) makes no sense to me. I don't even know how I came up with it. If someone can explain or give me an alternative that would give me a range from A6 to the end of the worksheet, that would make sense, that would be great.

   A                  B        C
1  Comment
2  Comment
3  Comment
4  Comment
5  Table Header
6  "green"
7  "blue"
8  "red"
9  "blue
10  "yellow"
11
12                    Total    2
question from:https://stackoverflow.com/questions/65940562/countifs-and-offset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

to count the negative we count the whole and subtract:

=COUNTA(A6:INDEX(A:A,MATCH("zzz",A:A)))-SUMPRODUCT(COUNTIFS(A6:INDEX(A:A,MATCH("zzz",A:A)),{"Blue","Yellow"}))

If the {"Blue","Yellow"} is are values in cells then:

=COUNTA(A6:INDEX(A:A,MATCH("zzz",A:A)))-SUMPRODUCT(COUNTIFS(A6:INDEX(A:A,MATCH("zzz",A:A)),Z1:Z2))

If the list of ignores can be expandable:

=COUNTA(A6:INDEX(A:A,MATCH("zzz",A:A)))-SUMPRODUCT(COUNTIFS(A6:INDEX(A:A,MATCH("zzz",A:A)),Z1:INDEX(Z:Z,MATCH("zzz",Z:Z))))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...