# Calculation with comma separated values in a cell

#### lind33

##### New Member
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

##### New Member
@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.

### Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

#### Peter_SSs

##### MrExcel MVP, Moderator
Is there a better way of writing this formula which works fine both for single and double digits?

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)

Replies
5
Views
170
Replies
20
Views
425
Replies
3
Views
78
Replies
13
Views
472
Replies
1
Views
67

1,127,123
Messages
5,622,870
Members
415,935
Latest member
kes1973

### 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.

### Which adblocker are you using?

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

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