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
 
Could you structure your age ranges at the top like this (make sure they are numbers, not numbers stored as text) and then use this standard-entry formula, copied across and down? This also avoids the use of the volatile function INDIRECT.

Book1
ABCDEFGH
1Age1112131415161
210203040506099
31,5,14,20,30,45,412210200
41,2,3,4,89,15,22,23,99,24,25,26,274160002
511,11,41,52,79,900200112
622,22,400021000
Sheet4
Cell Formulas
RangeFormula
B3:H6B3=COUNT(1/(LOOKUP(0+MID(SUBSTITUTE($A3,",",REPT(" ",100)),ROW(INDEX($A:$A,1):INDEX($A:$A,LEN($A3)))*100-99,100),$B$1:$H$1)=B$1))
Good work
thanks dear
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Could you structure your age ranges at the top like this (make sure they are numbers, not numbers stored as text) and then use this standard-entry formula, copied across and down? This also avoids the use of the volatile function INDIRECT.

Book1
ABCDEFGH
1Age1112131415161
210203040506099
31,5,14,20,30,45,412210200
41,2,3,4,89,15,22,23,99,24,25,26,274160002
511,11,41,52,79,900200112
622,22,400021000
Sheet4
Cell Formulas
RangeFormula
B3:H6B3=COUNT(1/(LOOKUP(0+MID(SUBSTITUTE($A3,",",REPT(" ",100)),ROW(INDEX($A:$A,1):INDEX($A:$A,LEN($A3)))*100-99,100),$B$1:$H$1)=B$1))
hi
is it possible to apply this formula for a specif cell not for a row... i mean i want to apply as cell index instead of row index because with row index the file hanged every time
so please help in this matter thanks
 
Upvote 0
hi
is it possible to apply this formula for a specif cell not for a row... i mean i want to apply as cell index instead of row index because with row index the file hanged every time
so please help in this matter thanks
I don't know what you mean by this.
 
Upvote 0
the file hanged every time

If you have performance problems with your file, you may want to think of a macro as an alternative.

Keep the following structure with your data:
Book1
ALAMANAOAPAQARAS
1Age01-1011-2021-3031-4041-5051-6061-150
21,2,11,21,31,322112
311,11,41,52,70,902112
422,22,4021
Sheet


The process with 10,000 records takes 2 seconds with the following macro:

VBA Code:
Sub count_unique_comma()
  Dim a As Variant, b As Variant, n As Variant, i As Long, j As Long
  a = Range("AL2", Range("AL" & Rows.Count).End(xlUp)).Value
  b = Application.Transpose(Range("AM1:AS1").Value)
  ReDim c(1 To UBound(a), 1 To UBound(b))
  
  For i = 1 To UBound(a)
    For Each n In Split(a(i, 1), ",")
      For j = 1 To UBound(b)
        If Val(n) >= Val(Split(b(j, 1), "-")(0)) And Val(n) <= Val(Split(b(j, 1), "-")(1)) Then
          c(i, j) = c(i, j) + 1
          Exit For
        End If
      Next
    Next
  Next
  Range("AM2").Resize(UBound(a), UBound(b)).Value = c
End Sub
____________________________________________________________________
HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (count_unique_comma) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
____________________________________________________________________

Anyway I attach my file so you can see how it works

 
Upvote 0

Forum statistics

Threads
1,215,337
Messages
6,124,340
Members
449,155
Latest member
ravioli44

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