Variable number formatting formula

CaptainGravyBum

Board Regular
Joined
Dec 1, 2023
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a formula in column A which is building a specific number format based on the characters provided from column B. This has been working fine when it was a fixed amount of numbers, but the spanner in the works is we now have text in addition to a the number. I've tried to adjust my formula to accommodate, but I can't get it right. Can anyone help?

Book1.xlsx
AB
1+++85931489-0285931489-2
2+++85947129-0185947129-1
3GECV8595251101GECV85952511-1
4GECV8595251101GECV85952511-1
Sheet1
Cell Formulas
RangeFormula
A1:A4A1=IF(ISNUMBER(SEARCH("GEC",B1)),TEXT(LEFT(B1,12),"+++####00000000-")&TEXT(RIGHT(B1,LEN(B1)-FIND("-",B1)),"00"),TEXT(LEFT(B1,8),"+++00000000-")&TEXT(RIGHT(B1,LEN(B1)-FIND("-",B1)),"00"))
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
It looks like you have shown us what it is currently returning.
Can you show us what you WANT it to return?

Also, please sure to show us any other structures and desired results, for any other entries you may have that don't fall into one of the two format/structures you have shown in your example.
 
Upvote 0
Would something like this work for you ?
Excel Formula:
=LET(bIsTxt,ISERROR(--LEFT(B1,1)),
     iStart,IF(bIsTxt,5,1),
     IF(bIsTxt,LEFT(B1,iStart-1),"") & TEXT(--MID(B1,iStart,8),"+++00000000-") & TEXT(TEXTAFTER(B1,"-"),"00"))
 
Upvote 1
It looks like you have shown us what it is currently returning.
Can you show us what you WANT it to return?

Also, please sure to show us any other structures and desired results, for any other entries you may have that don't fall into one of the two format/structures you have shown in your example.
There will only be these two structures in the data.
The lines without text should be in this format
+++85947129-01
and the lines with text will need to be
+++GECV85952511-01
 
Upvote 0
Would something like this work for you ?
Excel Formula:
=LET(bIsTxt,ISERROR(--LEFT(B1,1)),
     iStart,IF(bIsTxt,5,1),
     IF(bIsTxt,LEFT(B1,iStart-1),"") & TEXT(--MID(B1,iStart,8),"+++00000000-") & TEXT(TEXTAFTER(B1,"-"),"00"))
Hi Alex,
This is close, but the +++ needs to be at the beginning, I have added example results above.
 
Upvote 0
How about this:
Excel Formula:
="+++" & LEFT(B1,FIND("-",B1)) & TEXT(TEXTAFTER(B1,"-"),"00")

Results:
1721224952577.png
 
Upvote 1
Solution
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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