Search code examples
google-sheetsconcatenationarray-formulasstring-concatenationtextjoin

Is textjoin optimal for writing an arrayformula with variables?


Desired outout for this formula is

={
 ARRAYFORMULA(REGEXREPLACE(

List of names from e.g. A2:A25 like Abraham, Bonaparte, Cassius...

; ", $"; ))}

The list of names from A2:A25 must be presented with an If/Else and a comma between more than 1 name like this:

 IF('Abraham'!B2:F7<>""; 'Abraham'!A1&", "; )&
 IF('Bonaparte'!B2:F7<>""; 'Bonaparte'!A1; )

I have tried and failed with this:

=ARRAYFORMULA({""; "=ARRAYFORMULA({
"&TEXTJOIN(";"; 1;"

={
 ARRAYFORMULA(REGEXREPLACE(
 IF('Abraham'!B2:F7<>""; 'Abraham'!A1&", "; )&
 IF('Bonaparte'!B2:F7<>""; 'Bonaparte'!A1; ); ", $"; ))}

";)
)}
}

Any ideas?

Example


Solution

  • try:

    ={"";ARRAYFORMULA("=ARRAYFORMULA(REGEXREPLACE(TRIM("&TEXTJOIN("&"; 1; 
     IF(A1:A<>""; "IFERROR(IF("&A1:A&"!B2:F7<>""""; "&A1:A&
     "!A1&"", ""; ); {""""\""""\""""\""""\""""})"; ))&"); "",$""; ))")}
    

    0