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
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