count unique comma separated values from a single cell in excel

azad092

Board Regular
Joined
Dec 31, 2019
Messages
198
Office Version
  1. 2007
Platform
  1. Windows
Age1Y-10Y11Y-20Y21Y-30Y31Y-40Y41Y-50Y51Y-60YAbove 60Y
1,5,14,20,30,45,410000000
i want to calculate different age stages using comma separated value formula but it not works properly
how i can do this...
1,5 should be count in 1Y-10Y , 20 should be count in 11Y-20,30 should be count in 21Y-30Y and 45,41 should be count in 41Y-45Y
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi,

Welcome to MrExcel.
I am afraid that you problem, as stated, is very difficult to solve. The principal idea of Excel is that you put information in cells and then process it using formulas.
The principal idea which makes in work correctly is that you put one piece information per cell. It is sometimes called First Normal Form (1 NF).

You design violates the 1 NF principle, because
  • The Age field contains many numbers in one cell.
  • The fileds in the header contain both the lower and upper age limit, which is two pieces of information.
Therefore I strongly advise you to represent your data in a different form, with one number per cell, and then there are muttiple methods to do waht you want.

J.Ty.
 
Upvote 0
Hi,

Welcome to MrExcel.
I am afraid that you problem, as stated, is very difficult to solve. The principal idea of Excel is that you put information in cells and then process it using formulas.
The principal idea which makes in work correctly is that you put one piece information per cell. It is sometimes called First Normal Form (1 NF).

You design violates the 1 NF principle, because
  • The Age field contains many numbers in one cell.
  • The fileds in the header contain both the lower and upper age limit, which is two pieces of information.
Therefore I strongly advise you to represent your data in a different form, with one number per cell, and then there are muttiple methods to do waht you want.

J.Ty.
thanks for reply
now guide me can we use this formula LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1),",",""))+1 with countifs function if possible plz gude how....
 
Upvote 0
I am afraid that you data representation is so bad, that you probably cannot do this using formulas. VBA solution is possible, but still the change of data layout is the right way.

J.Ty.
 
Upvote 0
Hi azad092, welcome to the board and happy new year:

How about this array formula (Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.)

Book1
ABCDEFGH
1Age1Y-10Y11Y-20Y21Y-30Y31Y-40Y41Y-45Y46Y-50Y51Y-55Y
21,5,14,20,30,45,412210200
31,2,3,4,15,22,23,24,25,26,274160000
Hoja2
Cell Formulas
RangeFormula
B2:H3B2{=SUM(IF(ISNUMBER(SEARCH(","&ROW(INDIRECT(LEFT(B$1,SEARCH("Y",B$1)-1)+0&":"&MID(B$1,SEARCH("-",B$1)+1,2)+0))&",",","&$A2&",")),1))}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
You can reduce the formula if you put the age ranges as follows, without the "Y", we know that it refers to "Year", then it can be omitted.

Book1
ABCDEFGH
1Age01-1011-2021-3031-4041-5051-6060-99
21,5,14,20,30,45,412210200
31,2,3,4,89,15,22,23,99,24,25,26,274160002
Sheet2
Cell Formulas
RangeFormula
B2:H3B2{=SUM(--ISNUMBER(SEARCH(","&ROW(INDIRECT(SUBSTITUTE(B$1,"-",":")))&",",","&$A2&",")))}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


Array formulas
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself.
 
Last edited:
Upvote 0
You can reduce the formula if you put the age ranges as follows, without the "Y", we know that it refers to "Year", then it can be omitted.

Book1
ABCDEFGH
1Age01-1011-2021-3031-4041-5051-6060-99
21,5,14,20,30,45,412210200
31,2,3,4,89,15,22,23,99,24,25,26,274160002
Sheet2
Cell Formulas
RangeFormula
B2:H3B2{=SUM(--ISNUMBER(SEARCH(","&ROW(INDIRECT(SUBSTITUTE(B$1,"-",":")))&",",","&$A2&",")))}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.


Array formulas
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself.
thanks for your guideline ,but i still facing the problem. by using your suggested formula i can only get 1 in result. can you mail me the excel file in which you have apply this formula and also tell in which office you have apply this formula because i am using ms office2007
 
Upvote 0
You can copy the example and paste in your excel sheet:

1577938994633.png


Again I remind you that it is an array formula.
You must put this in the cell B2

=SUM(--ISNUMBER(SEARCH(","&ROW(INDIRECT(SUBSTITUTE(B$1,"-",":")))&",",","&$A2&",")))

Edit the formula and press the Control+Shift+Enter keys
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

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