简体   繁体   中英

Excel - returning the values from a range starting with the first non-blank value

I have a pivot table that shows the number of patients that collected medication in different months, grouped in columns according to month of first treatment.

图片

To the right of the Pivot Table is another table where I want to show the columns from the Pivot Table side by side, with the first cell in each column being the first non-blank cell in that particular column. Put in a different way, I want to show the information in the Pivot Table but without the blank spaces above the first non-blank value in each column.

In the spreadsheet above, I have experimented with the following formula in the rightmost table:

=INDEX(B7:B20;MATCH(TRUE;INDEX(B7:B20<>"";0);0))

As you can see from the attached image, this formula does not give me what I'm looking for. It keeps returning the same first non-blank value in each column until it hits the row in the Pivot Table where that value shows up. Also, after going through all the cells, it keeps returning the cell in the last column of the Pivot Table over and over again.

Any ideas on how to correct this?

Based on your provided information, use this formula in cell M6 and then copy over and down:

=IF(ROWS(M$5:M5)>COUNT(B$6:B$19),"",INDEX(B$6:B$19,SMALL(INDEX((ROW(B$6:B$19)-5)*(ISNUMBER(B$6:B$19)),),COUNTBLANK(B$6:B$19)+ROWS(M$5:M5))))

And it looks like your regional argument delimiter is a semicolon instead of a comma, so here's the semicolon version:

=IF(ROWS(M$5:M5)>COUNT(B$6:B$19);"";INDEX(B$6:B$19;SMALL(INDEX((ROW(B$6:B$19)-5)*(ISNUMBER(B$6:B$19)););COUNTBLANK(B$6:B$19)+ROWS(M$5:M5))))

From what I understand you want to skip blanks. This formula should work for text and numbers in column B

=IFERROR(INDEX(B$7:B$30,SMALL(IF(1-(B$7:B$30=""),IF(1-(B$7:B$30=""),ROW(B$7:B$30)-ROW(B$7)+1)), ROWS($F$7:F7))),"")

Use CTRL+Shift+Enter when entering it, as it is an array-formula

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