Reputation: 3827
I need extract numbers with leading zeros from mixed cells?
Example cell A1 content:
A1: 0012 SomeText
I need in cell B1 only numbers with leading zeros:
B1: 0012
If I put formula =TEXT(LEFT(A1;FIND(" ";A1));"@")
in cell formatted as General I get only numbers without leading zeros 12
.
If I put formula in cell formatted as Text formula doesn't work, it shows formula text.
Upvotes: 1
Views: 1789
Reputation: 55048
=TEXT(LEFT(A1;FIND(" ";A1));REPT("0";FIND(" ";A1)-2)&"#")
=TEXT(LEFT(A1,FIND(" ",A1)),REPT("0",FIND(" ",A1)-2)&"#")
The previous versions raise the question where the trailing space got lost.
Function LZERO(ZeroString As String) As String
LZERO = Split(ZeroString)(0)
End Function
e.g. =LZERO(A1)
Upvotes: 1
Reputation: 23285
Assuming your text is ####[space]xxxx
, you can pull the numbers with LEFT()
and SEARCH()
:
=TRIM(LEFT(A1;SEARCH(" ";A1)-1))
Upvotes: 4