Calculation with comma separated values in a cell

lind33

New Member
Joined
Jun 25, 2019
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
I have an example ordered comma separated list in a cell. Values are comma separated. they can be 1 digit or 2 digits.

Book2.xlsx

I'm trying to get the difference between the first value and the last value, and add 1 to the result. This is what I tried to do:

B2: = (RIGHT(A2,1)-LEFT(A2,1))+1

This works fine if all the values are single digit, but if the last value is two digits, then it doesn't give the correct result.

Is there a better way of writing this formula which works fine both for single and double digits? please. thanks

On the link to excel file above, there are some data and expected results, and how the expected results obtained.
 
@lind33
Mind you The other formula should be some thing like
Excel Formula:
=IFERROR((IF(LEFT(RIGHT(A1,SEARCH(",",A1)),1)=",",RIGHT(A1,SEARCH(",",A1)-1),RIGHT(A1,SEARCH(",",A1)))-LEFT(A1,SEARCH(",",A1)-1))+1,0)
yes, thanks. that works too.
 
Upvote 0

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.
Is there a better way of writing this formula which works fine both for single and double digits?
What about ..

lind33.xlsm
ABC
1DATAEXPTECTED RESULT
21,3,7,1010
310,101
41,4,99
50
61,55
74,52
83,7,86
Sheet1
Cell Formulas
RangeFormula
C2:C8C2=IF(A2="",0,RIGHT(SUBSTITUTE(A2,",",REPT(" ",20)),20)-LEFT(A2,FIND(",",A2&",")-1)+1)
 
Upvote 0

Forum statistics

Threads
1,215,018
Messages
6,122,703
Members
449,093
Latest member
Mnur

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