Seven Digit Number with Leading Zero's

Marc

Active Member
Joined
Feb 21, 2002
Messages
388
Hello Everyone, I have policy numbers given to me in a spreadsheet of various lengths. We use 7 digit policy numbers here and I need to convert these feed numbers to 7 digit numbers so that I can further break them down into three columns containing the “first 3”, “second 2” and “last 2” of the 7 digit number.

The best solution that I could imagine was to use this rather long if function to get the 7 digits and then use it to produce my three columns. The function just determines the length of the feed number and appends the appropriate amount of zero’s to the front.
Code:
=IF(LEN(A2)=1,"000000"&A2,IF(LEN(A2)=2,"00000"&A2,IF(LEN(A2)=3,"0000"&A2,IF(LEN(A2)=4,"000"&A2,IF(LEN(A2)=5,"00"&A2,IF(LEN(A2)=6,"0"&A2,IF(LEN(A2)=6,"0"&A2,A2)))))))

I can’t simply just format the feed column, because that will not allow me to produce the three columns. The function will work, I was just wondering if anyone has a better solution. Regards, Marc
7 digit policy number.xls
ABCDE
1FeedNo.7DigitsFirst3Middle2Last2
2100000010000001
31200000120000012
412300001230000123
5123400012340001234
61234500123450012345
712345601234560123456
8123456712345671234567
Sheet1
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Marc,

Using the suggestions above, you should be able to do what you want. If you do not wish to show the "intermediate" 7 digit column, you could combine it with your statement.

An example to pull the leftmost 3 digits from your original data:

=LEFT(TEXT(A2,"0000000"),3)

(assuming your data begins in A2)
 
Upvote 0
My apologies to everyone above, I wasn’t referencing my LEFT function correctly. :oops: It all works. Another one of those cases where the simple solution just couldn’t be seen right in front of my two eyes. :eek: Cheers!!
 
Upvote 0

Forum statistics

Threads
1,221,709
Messages
6,161,431
Members
451,705
Latest member
Priti_190

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