Set the length of a number

S

Sophie

Hello Everyone!

I have a column that needs to be populated with a six
digit number. I start off with a number (in cell G2) that
can be between 1 and four digits in length. I have used
the function below.

=IF(LEN(G2)=1,"00000"&G2,IF(LEN(G2)=2,"0000"&G2,IF(LEN(G2)
=3,"000"&G2,IF(LEN(G2)=4,"00"&G2,"Not"))))

It appears I might need expand this out to 13 digits. Can
anyone think of a better way as this formula will start
to get clumsy

TIA
Sxx
 
M

Mike Lewis

Hi Sophie,

This is one way:

=REPT("0",13-LEN(D4))&D4

where d4 is the number and 13 is the required length

Good Luck
Mike
 
G

Guest

Hi Mike

Very nice!
Thank you very much indeed

S
-----Original Message-----
Hi Sophie,

This is one way:

=REPT("0",13-LEN(D4))&D4

where d4 is the number and 13 is the required length

Good Luck
Mike

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top