Well, this seems to work with the test data, and if your real data is very similar to what you've shown, maybe it will be helpful.
Try the following formula anywhere in your sheet. It returns two columns.
={ {query(A1:B,"where B='"& index(sort(unique(B$1:B)),1,1) &"'",0)};
IF(counta(unique(B1:B))>1,{{"",""}; {query(A1:B,"where B='"& index(sort(unique(B$1:B)),2,1) &"'",0)}},{"Error 2",""});
IF(counta(unique(B1:B))>2,{{"",""}; {query(A1:B,"where B='"& index(sort(unique(B$1:B)),3,1) &"'",0)}},{"Error 3",""});
IF(counta(unique(B1:B))>3,{{"",""}; {query(A1:B,"where B='"& index(sort(unique(B$1:B)),4,1) &"'",0)}},{"Error 4",""});
IF(counta(unique(B1:B))>4,{{"",""}; {query(A1:B,"where B='"& index(sort(unique(B$1:B)),5,1) &"'",0)}},{"Error 5",""});
IF(counta(unique(B1:B))>5,{{"",""}; {query(A1:B,"where B='"& index(sort(unique(B$1:B)),6,1) &"'",0)}},{"Error 6",""})}
This counts how many unique values are in your column B, and then does a query for each unique value. The complexity was in stacking the results appropriately. Note how the blank rows are added, just after each IF
statement check. This seems to work, but there may be a better or more efficient way that someone can suggest.
There is an overall array, shown by the {...}, that begins and ends the formula. There is a secondary array for each IF
statement, and within that are two third level arrays, one for the blank row, and one for the QUERY
statement results. Let me know if any of this is unclear.
Note that the formula needs to be extended if you may have several more possible regions (or values) in column B. Just duplicate the second last row as many times as needed, and adjust the numeric values in it, and in the final row, so they follow in sequence. Better error checking may also be useful.
