If we can assume that the numeric group labels in col A are sequential, then I think this will achieve what you need:
- Enter the numeric label you are wanting to extract (16 in your example) into cell E1
- Note that
=MATCH(E1,A:A,0)
gives us the row number where group 16 starts, which is the first row we want to copy. Similarly,=MATCH(E1+1,A:A,0)
gives us the row number where group 17 starts, which is one row below the last row we want to copy. (Unfortunately that's not true for the very last group of code, but to rectify that you just need to add a dummy number at the very bottom of the data in col A.) - Enter the formula
=IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1),"")
in F1. That should copy the first value of the selected code block --[DO] ADD TO QUEUE P
in your example. - Copy F1 down as many rows as the largest code block is likely to be.
- The one problem with that is that it will put
0
whenever it copies a blank row. So you have to explicitly check for that case, e.g. by changing the formula in F1 to=IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),IF(ISBLANK(INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"",INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"")