Possible "CODE" formula enhancement/extension

Celticshadow

Active Member
Joined
Aug 16, 2010
Messages
419
Office Version
  1. 365
Platform
  1. Windows
Hi Forum

I have a formula that looks at a cell with three numbers contained within and it then rearranges them to replace any fig greater than a 5 with a 0 (zero). Thus if cell contains 541 then formula will change it to 041. However I have a couple of problems I would like solving by adding to the existing formula as below

The formula I am using in my spreadsheet is -

=IF(CODE(LEFT(B5)) > 52, 0, LEFT(B5))& IF(CODE(MID(B5,2,1)) > 52, 0, MID(B5,2,1))& IF(CODE(RIGHT(B5)) > 52, 0, RIGHT(B5))

1. If there is say a 51 in the cell then the formula changes that to 011 when infact I require 01 or if it had a 77 in the cell then it would change that to 000 when infact I require 00 or 22 would be changed to 222 instead of 22 etc.

2.If there is just a single figure in the cell such as a 1 or a 2 or a 3 etc then it just shows #VALUE! in the cell, when I would like it to show it as is, ie a 1 or a 2 or a 3 etc.

Any pointers to extend enhance the formula to help solve my query will be much appreciated.

I hope the above makes some semblance of sense if not please do not hesitate to ask for further clarity.

Regards
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Hi Fluff

I am using office 365 and Windows 10 and have updated profile accordingly.

Regards
 
Upvote 0
Thanks for that.
How about
Excel Formula:
=LET(m,MID(B5,SEQUENCE(,LEN(B5)),1),CONCAT(IF(m+0>4,0,m)))
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,199
Members
453,022
Latest member
RobertV1609

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