Numerical difference between 2 characters

smoothman

New Member
Joined
Jul 1, 2009
Messages
12
Hi all,

Was wondering if you could help me.
How do I write in a formula to get the numerical difference between two characters.

So difference between a and c is 2.
Difference between h and q is 9..

If the first character is after the second, for example X and B then I want to count till the end and back, so y z a b .. difference is 4

Thanks
 
You are welcome.
Glad we were able to help!

Note that if you have the possibility of mixed cases (some upper case, some lower case), but don't care about the case and want to treat them all the same, then Fluff's solution will work better, as he uses the UPPER function to convert them all to UPPER case before comparing.
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You could also handle the wrapping with the MOD() function like this if you wanted:
Excel Formula:
=MOD(CODE(UPPER(B1))-CODE(UPPER(A1)),26)
 
Upvote 0
You could also handle the wrapping with the MOD() function like this if you wanted:
Excel Formula:
=MOD(CODE(UPPER(B1))-CODE(UPPER(A1)),26)
Brilliantly clever and concise!
I wish I had thought of that!
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,542
Members
449,169
Latest member
mm424

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