Forum Discussion
tonyceccato
Microsoft
Jan 23, 2026Help with a Formula
Below is a formula I created to return specified rows and columns for a sheet named Detail and in the case or column 49 detect if there are comma separated values and explode them into separate colum...
Lorenzo
Jan 26, 2026Silver Contributor
Hi tonyceccato
- Why selecting range Detail!$A:$BZ when you actually use max. Detail!$A:$BP (col. 68)?
- As already suggested by VBasic2008, Format your data as Table if possible. Range Detail!$A:$BP means 1 million rows * 68 cols
In the below option:
- Assumed column Detail!BP:BP has no blank/empty cell(s) between the 1st and last used row in that column. This to resize/shrink your data range (Detail!$A:$BZ) to what's actually required (base + columns to split only)
- Should they exist in columns to split, strings like: " , Peach ,Grapes", "Peach,Strawberry, ,Raspberry,,,"... are managed to prevent extra columns when splitting *
=LET(
DataRange, Detail!A1:BZ1000,
CountifCriteriaRange, B16:B25,
delim, CHAR(44),
nbspace, CHAR(160),
Normalize, LAMBDA(str,
LET(
ReplacedNbs, SUBSTITUTE(str, nbspace, "" ),
ReplacedEmpty, REGEXREPLACE(ReplacedNbs, "(^\s*,\s*|,\s*(?=,|$))", "" ),
TRIM( REGEXREPLACE(ReplacedEmpty, "\s*,\s*", "," ) )
)
),
SplitToCols, LAMBDA(array,[normalized],
LET(
Normalized, IF( normalized = TRUE, array, Normalize(array) ),
Thunk, LAMBDA(x, LAMBDA(x) ),
Split, LAMBDA(array, IF( LEN(array), TEXTSPLIT(array, delim,, TRUE ), "" ) ),
ThunkSplit, LAMBDA(accum,array, Thunk( Split( array ) ) ),
arrThunks, SCAN(0, Normalized, ThunkSplit ),
ExpandThunk, LAMBDA(rw,cl, INDEX( INDEX( arrThunks, rw, 1 )(), 1, cl ) ),
MaxOutCols, MAX( LEN(Normalized) - LEN( SUBSTITUTE( Normalized, delim, "" ) ) ) +1,
Splitted, MAKEARRAY( ROWS(array), MaxOutCols, ExpandThunk ),
IFERROR( Splitted, "" )
)
),
RowsBP, COUNTA( Detail!BP:BP ),
NormalizedBW, Normalize( TAKE( CHOOSECOLS(DataRange, 49 ), RowsBP ) ),
ShrinkedData, HSTACK(
INDEX(DataRange, SEQUENCE( RowsBP ), {1,3,4,5,53,68} ),
NormalizedBW
),
FilteredData, FILTER( ShrinkedData,
IFNA( XMATCH( CHOOSECOLS(ShrinkedData, 6), CountifCriteriaRange ), 0 )
* ( CHOOSECOLS(ShrinkedData, 7) <> "" )
),
Base, CHOOSECOLS( FilteredData, {1,2,3,4,6} ),
StackedArrays, HSTACK( Base,
SplitToCols( CHOOSECOLS( FilteredData, 7 ), TRUE ),
SplitToCols( CHOOSECOLS( FilteredData, 5 ) )
),
SORT( UNIQUE( StackedArrays ), 1, TRUE )
)* RegEx by Copilot