Forum Discussion
DrExcel_Excel_MVP
Nov 20, 2023Copper Contributor
Leading and Trailing Zero in Excel
How to Remove Leading and Trailing Zeros in Excel We have a set of product codes like this : 000P2I290002M900 we want to make it like this P2I290002M9 which means removing all leading and trai...
PeterBartholomew1
Nov 20, 2023Silver Contributor
Hi. There are similarities.
My formula came out as
= MAP(list, TrimZeroλ)
where TrimZeroλ is given by
= LET(
nonzero, Explodeλ(text) <> "0",
first, XMATCH(TRUE, nonzero),
last, XMATCH(TRUE, nonzero, , -1),
MID(text, first, 1 + last - first)
)
Explodeλ is pretty standard
= LET(
n, LEN(text),
k, SEQUENCE(n),
MID(text, k, 1)
)