How can I create a dynamic view (filter) of a worksheet?

后端 未结 2 1160
难免孤独
难免孤独 2021-01-15 18:11

I\'m trying to modify a an excel file to improve its functionality, but unfortunately I don\'t have much experience with excel.

To explain my problem, let\'s say I h

相关标签:
2条回答
  • 2021-01-15 18:33

    You can achieve this using array formulas. Suppose that your data is in columns A, B and C in worksheet WS1. Enter the following formula in cell A1 on worksheet WS2:

    =INDEX('WS1'!$A:$A,SMALL(IF('WS1'!$A:$A=1,ROW(INDIRECT("1:"&COUNTA('WS1'!A:A)))),ROWS('WS1'!$A$1:$A1)))
    

    Confirm this formula using Ctrl-Shift-Enter to indicate that this is an array formula. As a result, you will see curly brackets {} around it.

    Similarly, enter the following array formulas in cells B1 and C1 on worksheet WS2:

    =INDEX('WS1'!$B:$B,SMALL(IF('WS1'!$A:$A=1,ROW(INDIRECT("1:"&COUNTA('WS1'!A:A)))),ROWS('WS1'!$A$1:$A1)))       
    =INDEX('WS1'!$C:$C,SMALL(IF('WS1'!$A:$A=1,ROW(INDIRECT("1:"&COUNTA('WS1'!A:A)))),ROWS('WS1'!$A$1:$A1)))
    

    Then select cells A1, B1 and C1 on worksheet WS2 and drag the right bottom corner all the way down as far as needed to contain all rows. Note that if you drag down too far, you will see #NUM. To avoid that, wrap the formulas in an IFERROR() formula (for Excel 2007 and later), as in

    =IFERROR(INDEX('WS1'!$A:$A,SMALL(IF('WS1'!$A:$A=1,ROW(INDIRECT("1:"&COUNTA('WS1'!A:A)))),ROWS('WS1'!$A$1:$A1))),"")
    

    The contents of the columns on worksheet WS2 get updated automatically if values in column A on WS1 are adjusted.

    A somewhat more efficient solution uses a helper column, lets say on worksheet WS3. It first calculates the indices of the relevant rows with the following formula (as an array formula in A1):

    =IFERROR(SMALL(IF('WS1'!$A:$A=1,ROW(INDIRECT("1:"&COUNTA('WS1'!A:A)))),ROWS('WS1'!$A$1:$A1)),"")
    

    Then enter the following formulas in B1, C1 and D1 (regular, not array formula):

    =IF(ISBLANK($A1),"",INDEX('WS1'!$A:$A,$A1))
    =IF(ISBLANK($A1),"",INDEX('WS1'!$B:$B,$A1))
    =IF(ISBLANK($A1),"",INDEX('WS1'!$C:$C,$A1))
    

    and select and drag down.

    You can find an uploaded example workbook here

    0 讨论(0)
  • 2021-01-15 18:52

    Another way of doing this: create a sequential key column to the left of the main table in sheet WS1, then use vlookup in WS2 to retrieve only those rows, using the row number on WS2 as the lookup key.

    E.g. suppose your data are in WS1!C2:D8, and you only want the rows where column D has the value "a". Then enter the following in B2, and paste down into B2:B8:

    =IF(D2="a",ROW(),"")
    

    Then enter the following in A2, and pasted down into A2:A8:

    =IF(B2="","",RANK(B2,$B$2:$B$8,-1))
    

    Finally, enter this formula in WS2!A1 and paste across and down as far as necessary (to be on the safe side, as far as your original table went in WS1):

    =IF(ROW() > MAX(Sheet1!$A$2:$A$8),"",VLOOKUP(ROW(),Sheet1!$A$2:$D$8,COLUMN()))
    
    0 讨论(0)
提交回复
热议问题