Need to convert numbers to text in a specific format

solved

Hi all, thanks in advance

I work in the inventory of a retail store where we need to print the cost of our product on our barcode, but in our own text code. For example, our code is the word "Phone Diary" where P is 1, H is 2 and so on till Y is 0. So if the cost of our product is 457 the code we write on our barcode is NEI.

The only exception to the rule is when the cost of the product has consecutive number like 1668 then the second consecutive number is replaced with an X, so 1668 would be PDXA

just some random numbers with what their codes would be

346 OND

15558 PEXXA (multiple consecutive are all X )

9985 RXAE

1004 PYXN

1002 PYXH

sometimes we receive bills to barcode which have 200-300 products with different costs so it takes a long time to translate the costs to codes. Is there any way to formulate this ? Im a complete excel noob and have been learning basic functions online. I tried to make something with the (IF, Then) functions but i got lost, im sure there should be a better way to do it.

​

Just for Clarification ( P = 1, H = 2, O = 3, N = 4, E = 5, D = 6, I = 7, A = 8, R = 9, Y = 0, Consecutive number = X )

It would be possible for me to make a table of numbers from 1 to 1000 and the letters that represent them, but we do get products that cost upto 6000-7000 (INR) and it wouldnt be possible for me to make a sheet with all numbers and their codes upto 7000

Posted Apr 20, 2021, 6:42 AM UTC · edited

211
mh_mike2195•

Assuming your version of Excel has TEXTJOIN, try this and see if it does what you're looking for:

=TEXTJOIN("",1,INDEX($D$2:$D$12,MATCH(IF(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)=IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2)))-1,1),""),"X",--MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)),$E$2:$E$12,0)))

Assumes numbers are in A (starting A2), and you've setup your PHONE DIARY code conversion table in D2 thru E12 (w/X being listed/included).

Sample of results (gray cells have formula copied down): https://imgur.com/IaaUkWp

NOTE: You could setup your PHONE DIARY conversion chart on a whole other sheet and call the ranges from there instead if you wanted to.

3
gauravbellaniOP•

=TEXTJOIN("",1,INDEX($D$2:$D$12,MATCH(IF(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)=IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2)))-1,1),""),"X",--MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)),$E$2:$E$12,0)))

SOLUTION VERIFIED

2
Clippy_Office_AsstMOD•

You have awarded 1 point to mh_mike

^I ^am ^a ^bot, ^please ^contact ^the ^mods ^with ^any ^questions.

1
mh_mike2195•

In case you want, you could also do it with CONCAT (if you've got TEXTJOIN, you'll also have CONCAT):

=CONCAT(INDEX($D$2:$D$12,MATCH(IF(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)=IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2)))-1,1),""),"X",--MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)),$E$2:$E$12,0)))

Since we're not plugging in any separators, we don't really need to use TEXTJOIN.

Also, if you plan to copy that formula down past where data might end on (or might not-yet-be typed or pasted into) the A column -- we can wrap the whole thing inside an IF checking if there is something in A to convert. If so, convert normally, otherwise leave an empty "" blank behind. If you want/need that, here's how to do it:

=IF(A2="","",CONCAT(INDEX($D$2:$D$12,MATCH(IF(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)=IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2)))-1,1),""),"X",--MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)),$E$2:$E$12,0))))
1
gauravbellaniOP•

mate you're an absolute wizard, thankyou so much

Could you guide me on how to set up the code on another page and reference it from there ?

1
mh_mike2195•

Sure, just set that legend up on some other sheet in columns A and B (just like you saw them in D and E on the sample screenshot I showed earlier).

For example purposes, I set it up in columns A and B on a sheet named PDC (standing for Phone Diary Conversion). You could name the sheet anything you want -- just change the PDC! prefixes you'll see in the following formula accordingly:

For TEXTJOIN:

=IF(A2="","",TEXTJOIN("",1,INDEX(PDC!$A$2:$A$12,MATCH(IF(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)=IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2)))-1,1),""),"X",--MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)),PDC!$B$2:$B$12,0))))

For CONCAT:

=IF(A2="","",CONCAT(INDEX(PDC!$A$2:$A$12,MATCH(IF(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)=IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2)))-1,1),""),"X",--MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)),PDC!$B$2:$B$12,0))))
3
blkhrtppl291•

Truly an advanced user, I aspire to reach your level of competency one day!

1
mh_mike2195•

haha Thanks :) (but don't confuse years upon years of experience in a particular craft with full-on competency in other areas of Excel -- there's plenty of stuff I'm still learning about)

I just work with text (data cleaning) a lot, and trying to figure these kinds of things out probably intrigues me waaaaaay too much! haha

2
AutoModeratorMOD•

u/gauravbellani - Your post was submitted successfully.

Please read these reminders and edit to fix your post where necessary:

Failing to follow these steps may result in your post being removed without warning.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1
blkhrtppl291•

So I'm terrible at this kind of stuff, so I took a multi-step approach to your problem:

https://docs.google.com/spreadsheets/d/1mAoWWpEXla2JeQjfMT45ikhFDdcec2d-JFsm1F5Kz2Q/edit?usp=sharing

  1. Break the number into its digits
  2. Translate into the corresponding letter
  3. Combine the resulting letters into a word

Hope this can help you make your own working template!

EDIT: The code can be translated back into cost by changing "PHONEDIARY" in the formula to "1234567890".

1