I have a excel with the next structure in the first sheet
ID | Color | Size |
---|---|---|
001 | red | A |
002 | green | A |
002 | blue | A |
002 | blue | B |
I need the rows whose color is blue to be automatically copied to the second sheet(including the records that are later included in the first sheet) with only formulas without VBA
With the example
ID | Color | Size |
---|---|---|
002 | blue | A |
002 | blue | B |
I try to use the nex formula in the second sheet
=IF('Sheet1'!$B2="blue";'Sheet1'!A2;"")
and i got the following result
ID | Color | Size |
---|---|---|
002 | blue | A |
002 | blue | B |
but i need the unmatched rows not to appear even blank
is there any way to do this if VBA?
I use Excel 2010
Many thanks to all
It is possible without VBA as well if you use additional column in "Sheet1", for example "D" for your table. In "D1" write "Counter" Then write in "D2":
=IF(B2="blue";MAX($D$1:D1)+1;0)
and copy to rows below. This is an increasing counter of rows with blue values in B2 or 0.
Then in new sheet "Sheet2" copy header line ("ID", "Color, "Size") from "Sheet1" to "A1:C1".
In "A2" write:
=IFERROR(INDEX(Sheet1!$A$2:$C$100;MATCH(ROW()-1;Sheet1!$D$2:$D$100;COLUMN());"")
Copy "A2" cell through "C2", then whole line "A2:C2" until last row.
These functions look for ROW()-1 in "D" column of "Sheet1" and show the whole row if found. IFERROR hide other rows, because if not found #N/A will be shown in empty cells within your range.
$A$2:$C$100 - your source table in "Sheet1".
$D$2:$D$100 - counters' range.
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.