Leading zeros removed after a replace of non-numeric characters leaving only numeric charaters

PriorityOne

New Member
Joined
Nov 6, 2014
Messages
8
I need to remove the forward slashes and leave the results in a data set like the below. I keep losing the leading zeros when I do a replace all with / in the find and left the replace with blank even when the cells are formatted to Text. I am working in Excel 2010 with a regular .xlsx file - I know the csv tricks and what is necessary when I have pure numeric characters. the only thing that has worked is to put an apostrophe in front of the first characters in the first cell ('0019A in the example below) and then use the format painter to copy the format down to the other characters prior to doing the replace. I thought it might because the removal of the forward slash would make the characters numeric, lost it's text properties and removed the leading zeros, but the results are still in a cells formatted as Text. I found a formula that worked =IF(RIGHT(A1,1)="/",LEFT(A1,4),A1) which would maintain the leading zero if I did a copy paste special values into a general formatted cell. Can anyone explain why I can't use the replace function and why the formula would work with leading zeros in a general formatted cell?

0019A
0043/
0051/
0104/
0119/
0133/
0140/
0146/
0153/
0162A
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
When you remove the slash, Excel recognizes that your cell value is all digits and automatically assumes that you want it to be a number.

When you use the LEFT formula, it returns a text value, and if you copy/paste values, it preserves that text format. However, you will probably get an error indicator warning you that you have a "Number stored as text".
 
Upvote 0
Thank you. I was thinking that and yes, I have a warning about the number stored as text. So it makes a lot of sense now that the apostrophe would solve the issue which is what I thought. Is the apostrophe the only work around from a formatting standpoint?
 
Upvote 0
a
b
1
0019a0019a
2
0043/0043
3
0051/0051
4
0104/0104
5
0119/0119
6
0133/0133
7
0140/0140
8
0146/0146
9
0153/0153
10
0162a0162a

<tbody>
</tbody>

b1=SUBSTITUTE(A1,"/","")&"" copy down
 
Upvote 0
a
b
1
0019a0019a
2
0043/0043
3
0051/0051
4
0104/0104
5
0119/0119
6
0133/0133
7
0140/0140
8
0146/0146
9
0153/0153
10
0162a0162a

<tbody>
</tbody>

b1=SUBSTITUTE(A1,"/","")&"" copy down

This approach, or the one you used with LEFT/RIGHT combination, will produce a text value. If you copy/paste values, Excel will store it as text. You could also use a TEXT function on a set of data where it is already a number (e.g. =TEXT(A1, "0000") to leftpad with zeroes, and then copy/paste values. However, I personally find the apostrophe method more reliable, for my own peace of mind if nothing else.
 
Upvote 0
a
b
1
0019a0019a
2
0043/0043
3
0051/0051
4
0104/0104
5
0119/0119
6
0133/0133
7
0140/0140
8
0146/0146
9
0153/0153
10
0162a0162a

<tbody>
</tbody>

b1=SUBSTITUTE(A1,"/","")&"" copy down



I didn't realize I had more replies until I cleaned out my buried inbox. I apologize. This is a great solution and I appreciate the reply both MARZIOTULLIO and iliace !!!
 
Last edited:
Upvote 0
If I have understood correctly, there's another pretty easy way.

With the data as posted in post #1,
- Select the column
- Data ribbon tab - Text to Columns - Delimited - Next - Clear all check boxes except 'Other' and put a / in the 'Other:' box - Next - Select 'Text' as the column data format - Finish
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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