I have created a named function with signature PadInternal(base, width, paddingStr)
where:
base
is a string you want to add padding towidth
is the length of the individual chunkspaddingStr
is the string to pad with
PadInternal("Hello", 1, " ") = "H e l l o"
PadInternal("World", 3, "**") = "Wor**ld"
And here's the function:
Tag | Description |
---|---|
Name | PadInternal |
Scope | Workbook |
Comment | base : a string you want to add padding to | width : the length of the individual chunks | paddingStr : the string to pad with |
Refers To | =LAMBDA(base,width,paddingStr, IF(LEN(base)<=width, base, LET(LHS, LEFT(base, width), RHS, RIGHT(base, LEN(base) - width), LHS & paddingStr & PadInternal(RHS,width,paddingStr)))) |
=LAMBDA(
base,
width,
paddingStr,
IF(
LEN(
base
) <= width,
base,
LET(
LHS,
LEFT(
base,
width
),
RHS,
RIGHT(
base,
LEN(
base
) - width
),
LHS & paddingStr &
PadInternal(
RHS,
width,
paddingStr
)
)
)
)
Questions
As this is my first time using recursive Lambda functions in Excel, I'd like some feedback. In particular:
- Is my algorithm efficient - I was thinking something with
TEXTJOIN
may be faster? - How could this be improved to take a dynamic array as "base"?
- Can I have default values for the arguments?
- What about meta data (formatting of the tooltip, scope etc), are there other ways to make my function more accessible?
ChunkMyText
might do. :) \$\endgroup\$