Pad number (that comes from a formula) with zeros (before and after)

PeteWright

Well-known Member
Joined
Dec 20, 2020
Messages
505
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi all!

I have a table (containing a coordinate list) but for further processing I need the number to have the specific format "000.000" (exactly 7 characters long).
Some examples are:
123.456 > no changes
123.4 > pad with zeroes to 123.400
123 > pad with zeroes to 123.000
98.765 > pad with zeroes to 098.765
98 > pad with zeroes to 098.000

The tricky part (at least I think it is) that the number comes from a formula otherwise I'd try something like number format "000.000".

In addition I'd like to display a blank cell instead of a number, if any of a set of given cells are blank.
For example if any of the cells (A1, B1, C1, D1 or E1) is blank display nothing in F1 and the padded number otherwise.

Right now i have a huge formula for this like:
= IF(OR(NOT(ISBLANK(A1));NOT(ISBLANK(B1));NOT(ISBLANK(C1));NOT(ISBLANK(D1));NOT(ISBLANK(E1)));"_SOME_FORMULA_";"")
and the actual formula is also quite long which makes it less readable.
Is there a way to get rid of this?

Thanks in advance
Pete
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
As far as the format is concerned, would TEXT function work for you:

Excel Formula:
=TEXT(A1,"000.000")

(instead of A1 insert your data or formula)

As far as the blanks are concerned, something like this:

Excel Formula:
=IF(SUM(--(NOT(ISBLANK(A1:E1))))<>COLUMNS(A1:E1),"","SOME FORMULA")
 
Upvote 0
Another option is to use regular expressions in Excel (bp=before point, ap=afer point):
Excel Formula:
=LET(bp;REGEXEXTRACT(A1;"^[0-9]{1,3}(?=\.)?");
     ap;IFERROR(REGEXEXTRACT(A1;"(?<=\.)[0-9]{1,3}$");"");
     REPT("0";3-LEN(bp))&bp&"."&ap&REPT("0";3-LEN(ap)))
 
Upvote 0
= TEXT(A1,"000.000")
Nice, didn't know that one.
= IF(OR(A1:E1<>"");"_SOME_FORMULA_";"")
Didn't know that OR accepts a Range too, thanks. Learned something new.

Many thanks @hagia_sofia and @Phuoc with your suggestions I made up a pretty short formula

= IF(OR($A1:$E1<>"");TEXT(D1;"000.000");"")

which does exactly what I need.

Another option is to use regular expressions in Excel
Thanks for the idea, but I think I'll stick with what I have now since it's shorter :)
 
Upvote 0
Solution

Forum statistics

Threads
1,224,752
Messages
6,180,743
Members
452,996
Latest member
nelsonsix66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top