how would i change these cells?

bigdan

Well-known Member
Joined
Oct 5, 2009
Messages
840
Office Version
  1. 2013
Platform
  1. Windows
I have a spreadsheet of store numbers that I need to change around. The first 3 characters are always ABC, and then it follows with 2-4 digits. I need to make these all 4 digits, with the missing characters being made 0. So for example ABC1234 would stay as is, ABC123 would become ABC0123, and ABC12 would become ABC0012.

How would I do this?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Here is a UDF that seems to do what you are looking for.

Code:
Function FormatAlpha(s As String)
Dim L As String: L = left(s, 3)
Dim R As String: R = Replace(s, L, "")
FormatAlpha = L & Format(R, "0000")
End Function
 
Upvote 0
With a formula
=LEFT(A2,3)&TEXT(MID(A2,4,100),"0000")
 
Upvote 0
Here is another formula solution that you can consider...

=REPLACE(A2,4,0,REPT(0,7-LEN(A2)))
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

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