+ Reply to Thread
Results 1 to 16 of 16

Formula or Function for count value separated by commas (,)

  1. #1
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Formula or Function for count value separated by commas (,)

    Hello,

    We are lucking a function or Formula for count value seprated by comma (,)
    for eg
    18,22,15,11,7 then show 5

    18(500),22,15,11,7 then show 4.5

    18(200),22(600),15,11,7 then show 3.8


    pls help me solve above problem.. we googling above problem but can't find solution..

    thanks in advance.

    Santosh

  2. #2
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Formula or Function for count value separated by commas (,)

    Hi,

    What is the max count of numbers within a cell? Is it 5 as in the examples provided by you?

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: Formula or Function for count value separated by commas (,)

    I have noooo idea how you get 4.5 or 3.8, but this will give you the answer for the 1st sample...
    =LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Formula or Function for count value separated by commas (,)

    18,22,15,11,7 then show 5 --- There are five numbers, so result is 5.

    18(500),22,15,11,7 then show 4.5 --- There are four numbers and one with a parenthetical, so result is 4 plus the decimal of 500/1000 ?

    18(200),22(600),15,11,7 then show 3.8 --- There are three numbers, and two with parentheticals, so result is 3 plus the decimal of (200+600)/1000 ?

    What happens if the parenthetical values add up to more than 1000? e.g. "18(500),22(700),15,11,7". Is that 4.2? I assume it wouldn't be 3.12 since that could also be achieved with "18(100),22(20),15,11,7".

  5. #5
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Re: Formula or Function for count value separated by commas (,)

    Hi thanks for response to cbatrody , FDibbins & Paul

    cbatrody : yes this is my eg.. we provide u..

    FDibbins : sir we also don't know is it possible or not..

    Paul : "18(100),22(20),15,11,7". this ans will come 15,11,7 = 3 18(100) = .1 & 22(20) =.02 so total ans = 3.12

    Actually we devide = () value /1000

    hope now we clear all..

    thanks for all & we also add rep to all

    santosh

  6. #6
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Formula or Function for count value separated by commas (,)

    So what if decimals exceed 1,000 as mentioned by Paul? i.e, 500+700 =1,200, is it going to be 1.2+3 = 4.2?

    "18(500),22(700),15,11,7".

  7. #7
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Re: Formula or Function for count value separated by commas (,)

    Yes if decimal exceed 1000 then that value 1

  8. #8
    Forum Expert cbatrody's Avatar
    Join Date
    04-15-2014
    Location
    Dubai
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2,136

    Re: Formula or Function for count value separated by commas (,)

    Last one: How many decimals ( ) max a cell may have?

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Formula or Function for count value separated by commas (,)

    The following Function (insert into Standard Module) should do the trick. If the string of values is in A1, then in B1 use the formula

    =cdelim(A1)

    Can be filled down/across, copied elsewhere, etc. Whichever cell you want to parse, set that as the cell in the formula. It's currently coded to only work on one cell.
    Please Login or Register  to view this content.
    Last edited by Paul; 08-21-2014 at 03:19 PM. Reason: Forgot to dim variable i, woops. :)

  10. #10
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Re: Formula or Function for count value separated by commas (,)

    Yes it is.... Thanks Paul...ur provided UDF working as per my need...

    thanks a lot

    Actually when we run this UDF in main database then we got in few cell 1(300) or 2(500) data in following shape
    1(300) = 1(200-500), 1(600-900)
    2(500) = 2(0-500), 2(500-1000)

    actaully in few record between () full value exit insted of cacluated

    in this we analize whole data in between() small value first then higher value seccond

    for eg (600-900), (200-500) etc..
    Santosh
    Last edited by santosh226001; 08-21-2014 at 08:56 PM. Reason: after run in maid data face problem

  11. #11
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Formula or Function for count value separated by commas (,)

    I think this slight change should accommodate any parentheticals that contain math, e.g. 100+200, 500-100. I also found a mistake at the end of the tmpSum line, in which I was keeping too many characters. Luckily the Val function ditched the non-numeric characters at the end and still calculated properly. With the math functions, though, that wasn't working and I had to fix it. I ended up changing the Val function to the Evaluate function so it would actually perform the math shown in the parentheses, then include it in tmpSum. Hopefully that makes sense!
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Re: Formula or Function for count value separated by commas (,)

    Hi .. ur modified code work little bit difference from my need..

    currently when we count the length of 1,2,3(200-500).. function result show 1.7....
    but we want result 2.3 because
    1,2 =2
    & 3(200-500) =.3

    so result is 2.3

    pls suggest me where we change in fucntion so we got above result..


    Thanks

    Santosh

  13. #13
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Formula or Function for count value separated by commas (,)

    That is a math problem, not an Excel problem. The function is working exactly as intended.

    (200-500)/1000 is not 0.3, it is -0.3. So 2 + (-0.3) = 1.7

    What mathematic function do you think you could use to change negative values to positive ones, and how might you adjust the code to do so?

  14. #14
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Re: Formula or Function for count value separated by commas (,)

    ohhhh so it's Math problem...

    but We want this -ve value in +ve form.. actually above calucation is related to Road KM's ..
    3(200-500) define in Kilometer 3 between 200 mt to 500 mt so this area is 300 mt which we calcuate in length form .3

    thanks

  15. #15
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Formula or Function for count value separated by commas (,)

    What I'm saying is this:

    There are several ways to convert negative values to positive values.
    1. Multiply negative results by -1
    2. Get the absolute value of the result (always positive)
    3. Subtract the result from the result of subtracting the result from itself. (-300-(-300)-(-300)=300)
    4. Some other silly method.

    Obviously the first two methods are simple, and easy to code into my solution.

    Having said that, here's how the Abs function (absolute value) would be coded..

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    434

    Re: Formula or Function for count value separated by commas (,)

    Yes!!!! this work exactly what i want..


    Paul Thanks a lot !!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula to count values in single cell separated by commas
    By aimeecrystalaid in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-25-2017, 01:01 AM
  2. I have thousands of emails separated by commas, looking for a formula..
    By Sankeys in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-28-2014, 07:34 PM
  3. Replies: 5
    Last Post: 01-17-2014, 05:56 PM
  4. Replies: 4
    Last Post: 06-21-2012, 08:17 PM
  5. Replies: 5
    Last Post: 06-05-2012, 03:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1