SUBSTITUTE a Blank space...

Aitch

Board Regular
Joined
Jan 27, 2019
Messages
119
Office Version
  1. 2010
Platform
  1. Windows
If I have a cell with two digits - how can I use the SUBSTITUTE function to add an extra character to make the cell have 3 digits?

So a cell with 11 would turn in to 011 or A11

Thanks for your help!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
If I have a cell with two digits - how can I use the SUBSTITUTE function to add an extra character to make the cell have 3 digits?

So a cell with 11 would turn in to 011 or A11
You can use the TEXT function. For your first value...

=TEXT(B1,"000")

For your second value...

=TEXT(B1,"\A00")

or this...

=TEXT(B1,"""A""00")
 
Last edited:
Upvote 0
Great, thanks!

How can I use this with an IF function so it only operates on cells with 2 digits and not on cells with 3 digits?
 
Upvote 0
How can I use this with an IF function so it only operates on cells with 2 digits and not on cells with 3 digits?
Assuming the only thing in the cell are whole numbers...

=If(B1<100,TEXT(B1,"000"),"")

or

=If(B1<100,TEXT(B1,"\A00"),"")
 
Upvote 0
Unfortunately there will be letters in some of the cells

The format being plain text seems to break it - is there another way?
 
Upvote 0
Unfortunately there will be letters in some of the cells
You have to tell us this stuff... remember, we know nothing about your data except what you tell us.

See it this works for you...

=IF(AND(LEN(B1)=2,ISNUMBER(-B1)),TEXT(B1,"000"),"")

or this...

=IF(AND(LEN(B1)=2,ISNUMBER(-B1)),TEXT(B1,"\A00"),"")
 
Upvote 0
Sorry for being so vague!

This works great, thank you!
 
Upvote 0
Sorry for bothering you again!

The formula works great - except when the cell contains a number that begins with zero...

So 50 becomes A50 - but 05 stays the same, instead of becoming A05

Is there a way to fix this?

Thanks!
 
Upvote 0
The formula works if you have the text 05

Review the following:


4d54c2751bbffd354eed49430cf63db5.jpg


Or explain with images exactly what data you have, remember, as Rick said, we can not see your data.
 
Upvote 0
Thanks for the reply!

I've checked that the formula is text, and it's still not working...

This is the formula customised for my spreadsheet - is there a mistake in it?

=
IF(AND(LEN(O31)=1,ISNUMBER(-O31)),TEXT(O31,"\OO0"),IF(AND(LEN(O31)=2,ISNUMBER(-O31)),TEXT(O31,"\O0"),O31)))))
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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