Insert a 0, if not a number.

Gil149

Board Regular
Joined
Oct 11, 2010
Messages
144
Guys,
I need some help on finding and inserting a number in between characters. I need to go through the A column, cell by cell, and if the second to last character from the right is not a number, I need to insert number 0.

Example...
02AA1
02A34
02AA5

Would become...
02AA01
02A34
02AA05

I can find the cells, code wise...but I don't know how to add the 0...while maintaining the exact cell data!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
=IF(ISNUMBER(MID(A1,LEN(A1)-1,1)+0),A1,LEFT(A1,LEN(A1)-1)&"0"&RIGHT(A1,1))

There may be a more elegant way . . .
 
Upvote 0
Thanks guys! I didn't even think about that method! I am to used to the code end...really appreciate it.
 
Upvote 0
=if(isnumber(right(A1,2)),A1,left(A1,len(A1)-1) & "0" & right(A1,1))

This assumes that the last character in A1 is also a number, which was not established in the OP..
It's true for the 3 sample strings given, but I don't think that's a large enough sample to establish that assumption.

But if that's a true statement, that the last character will always be a number then I suggest a combination of Charles' and My Formulas

=IF(ISNUMBER(RIGHT(A1,2)+0),A1,REPLACE(A1,LEN(A1),0,0))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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