In this shared Google Sheet there are values in a range, contactenated in a specified order, how can I maintain the specified order while specifying 2 variables: A) when to combine the "header value" and "cell value" into a header/value pair and B) when to add a delimiter
A header/value pair are displayed with the following equation:
=ARRAYFORMULA(TRIM(SUBSTITUTE(TRIM(FLATTEN(QUERY(REGEXREPLACE(SORT(TRANSPOSE(
IF((A2:D4<>"")*(REGEXMATCH(A1:D1, "^\d+_")), "♥"&A1:D1&" "&A2:D4, )),
FLATTEN(A1:D1), 1), "\d+_", ),,9^9))), "♥", CHAR(10)))
All header values with a preceding number are displayed in order in the above image.
Goals However, as in the following image, there are times when it would be useful to
- Not to include the header value
- add one or more variable delimeters (ie
CHAR(10), " , "after the cell value string and other times when it would help to
Possible approach:
In the above image, a number + an underscore ex
1_Name(B1 )can represent a parameter to include the header/value pair and a number + tilda4~Math(A1) can represent a parameter to exclude the header valueZero or more delimeter variables (>1 represented by
&)can be provided after a pipe to designate the delimiters to include afer the resulting string (value or header/variable pair)
Since the above equation, already adds a CHAR(10) delimiter I believe it would make sense to specify values after a pipe to represent a delimeter variable. As in the image below, this parameter would be inserted into the formula in that space.
For example, in B1 the value after the pipe CHAR(10) & CHAR(10) would add two line spaces. In A1, the value after the pipe ", " would simply add a comma without a new line space.
The shared sheet is here.



