简体   繁体   中英

In Excel, How do I count the number of blank cells until the next non-blank cell

I have a spreadsheet which resembles the below. Column A is my data and Column B is what I am trying to achieve

         A           B
   +-----------+-----------+
1  | Some text |   A1:A3   |
   +-----------+-----------+
2  |           |           |
   +-----------+-----------+
3  |           |           |
   +-----------+-----------+
4  | Some text |   A4:A8   |
   +-----------+-----------+
5  |           |           |
   +-----------+-----------+
6  |           |           |
   +-----------+-----------+
7  |           |           |
   +-----------+-----------+
8  |           |           |
   +-----------+-----------+
9  | Some text |   A9:A9   |
   +-----------+-----------+
10 | Some text |  A10:A10  |
   +-----------+-----------+
11 |           |           |
   +-----------+-----------+
12 |           |           |
   +-----------+-----------+

As you can see, Column A just contains empty and non-empty cells (all cells, including empty ones, actually contain a formula). In column B, I need to return a range starting at the current row and ending at the first non-empty row, but only if Column A of the current row is not blank. The returned result is to be used within another function. For example B1 could be COUNTBLANK(A1:A3), although the actual function is not COUNTBLANK, but a custom function

Is this possible?

Thanks

Please add a letter at the bottom of your "occupied" ColumnA then try, in B1 and copied down:

=IF(A1="","","A"&ROW()&":A"&ROW()+MATCH("*",A2:A100,0)-1)  

Alternative to account for restriction mentioned by OP

=IFERROR(IF(A1="","","A"&ROW()&":A"&ROW()+MATCH("*",A2:A$1048576,0)-1),"A"&ROW()&":A"&ROW())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM