Custom Number Formatting

%3CLINGO-SUB%20id%3D%22lingo-sub-1927669%22%20slang%3D%22en-US%22%3ECustom%20Number%20Formatting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1927669%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20day%20folks!%26nbsp%3BI%20want%20to%20create%20a%20custom%20format%20to%20assign%20to%20a%20group%20of%20cells.%20Thank%20you%20in%20advance.%26nbsp%3B%20Mister%20Bob%20the%20Tomato%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20make%20entries%20in%20these%20two%20manners%3A%26nbsp%3B%3CSTRONG%3ED032CR20123456%20%3C%2FSTRONG%3E%3CEM%3Eand%26nbsp%3B%3C%2FEM%3E%3CSTRONG%3EC07CR20123456%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eautomatically%20convert%20to%3A%26nbsp%3B%3CSTRONG%3ED-032-CR-20-123456%20%3C%2FSTRONG%3E%3CEM%3Eand%26nbsp%3B%3C%2FEM%3E%3CSTRONG%3EC-07-CR-20-123456%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1927669%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1927755%22%20slang%3D%22de-DE%22%3ESubject%3A%20Custom%20Number%20Formatting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1927755%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F880269%22%20target%3D%22_blank%22%3E%40MisterBobTheTomato%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3EHere%20is%20an%20example%20with%20a%20formula.%3C%2FSPAN%3E%3C%2FSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22VIiyi%22%3E%3CSPAN%20class%3D%22JLqJ4b%20ChMk0b%22%3E%3CSPAN%3EThere%20are%20many%20ways%20and%20ways%20to%20get%20there%2C%20that's%20just%20one%20of%20the%20many.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFormula%3A%20%3DMID(A1%2C1%2C1)%26amp%3B%22-%22%26amp%3BMID(A1%2C2%2C3)%20%26amp%3B%22-%22%26amp%3BMID(A1%2C5%2C2)%20%26amp%3B%22-%22%26amp%3B%20MID(A1%2C7%2C2)%26amp%3B%22-%22%26amp%3BMID(A1%2C9%2C6)%3C%2FP%3E%3CP%3EResult%3A%20%3CSTRONG%3ED-032-CR-20-123456%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1934996%22%20slang%3D%22en-US%22%3ERe%3A%20Custom%20Number%20Formatting%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1934996%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F880269%22%20target%3D%22_blank%22%3E%40MisterBobTheTomato%3C%2FA%3E%26nbsp%3B%26nbsp%3B%20To%20explain%20Nikolino's%20response%2C%20the%20point%20is%3A%26nbsp%3B%20this%20cannot%20be%20done%20with%20a%20Custom%20format%20%3CU%3E%3CEM%3Eper%20se%3C%2FEM%3E%3C%2FU%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExcel%20considers%20D032CR20123456%20and%20C07CR20123456%20to%20be%20text%2C%20%3CU%3E%3CEM%3Enot%20numbers%3C%2FEM%3E%3C%2FU%3E.%26nbsp%3B%20Note%20that%20ISTEXT(A1)%20is%20TRUE.%26nbsp%3B%20And%20Excel%20does%20not%20provide%20any%20Custom%20formats%20for%20text%2C%20other%20than%20to%20display%20a%20prefix%20and%2For%20suffix%3B%20e.g.%20Custom%20%22prefix%20%22%40%22%20suffix%22%20.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20could%20write%20a%20macro%20(VBA%20Sub)%20that%20converts%20a%20selected%20range%20of%20such%20text%2C%20effectively%20applying%20Nikolino's%20suggestion%20%3CEM%3Ein%20situ%3C%2FEM%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20you%20could%20write%20an%20event%20macro%20that%20applies%20the%20same%20conversion%20to%20text%20when%20it%20is%20entered.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20in%20all%20cases%2C%20the%20result%20is%20%3CU%3E%3CEM%3Edifferent%20text%3C%2FEM%3E%3C%2FU%3E%2C%20unlike%20Custom%20formats%20that%20merely%20alter%20the%20appearance%20of%20an%20unchanged%20value.%26nbsp%3B%20For%20example%2C%20instead%20of%20IF(A1%3D%22D032CR20123456%22%2C...)%2C%20you%20would%20need%20to%20write%20IF(A1%3D%22D-032-CR-20-123456%22%2C...).%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Good day folks! I want to create a custom format to assign to a group of cells. Thank you in advance.  Mister Bob the Tomato

 

I want to make entries in these two manners: D032CR20123456 and C07CR20123456

automatically convert to: D-032-CR-20-123456 and C-07-CR-20-123456

2 Replies

@MisterBobTheTomato 

Here is an example with a formula.

There are many ways and ways to get there, that's just one of the many.

 

Formula: =MID(A1,1,1)&"-"&MID(A1,2,3) &"-"&MID(A1,5,2) &"-"& MID(A1,7,2)&"-"&MID(A1,9,6)

Result:  D-032-CR-20-123456

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.

@MisterBobTheTomato   To explain Nikolino's response, the point is:  this cannot be done with a Custom format per se.

 

Excel considers D032CR20123456 and C07CR20123456 to be text, not numbers.  Note that ISTEXT(A1) is TRUE.  And Excel does not provide any Custom formats for text, other than to display a prefix and/or suffix; e.g. Custom "prefix "@" suffix" .

 

You could write a macro (VBA Sub) that converts a selected range of such text, effectively applying Nikolino's suggestion in situ.

 

Or you could write an event macro that applies the same conversion to text when it is entered.

 

But in all cases, the result is different text, unlike Custom formats that merely alter the appearance of an unchanged value.  For example, instead of IF(A1="D032CR20123456",...), you would need to write IF(A1="D-032-CR-20-123456",...).