+ Reply to Thread
Results 1 to 9 of 9

count of comma separated values

  1. #1
    Registered User
    Join Date
    05-11-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    37

    count of comma separated values

    hi
    i have a data like this in a string.
    K,L,M,N,O
    I want to count the total values that are separated by comma and store it in a variable i.e. it has to return 5..
    Please help me if you can
    Thanks,
    bujji

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: count of comma separated values

    Hi

    One way, could be this.

    =IF(LEN(TRIM(A1))>0,LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1,0)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: count of comma separated values

    =len(a1)-len(substitute(a1,",",""))+1
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: count of comma separated values

    bujji1305,

    If this string is in cell A1:
    K,L,M,N,O

    Then in cell B1, try:
    =IF(RIGHT(A1,1)<>",",LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1,LEN(A1)-LEN(SUBSTITUTE(A1,",","")))
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Registered User
    Join Date
    05-11-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: count of comma separated values

    Hi Fotis1991,martindwilson,stanleydgromjr ....... no code is working for me....

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: count of comma separated values

    can you be more specific what doesn't work ?

  7. #7
    Registered User
    Join Date
    05-11-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: count of comma separated values

    Actually i have a .csv file from which the data is imported to excel report... From .csv, i need to split the semi colon separated values in a column by giving condition at report generator form i gave condition as K,L,M:K i.e., i need to split data in K to k,L,M
    so i get this value in a string a in my code as
    a=instr(1,splitcol,",")
    now i get a value as K,L,M so i want 'a' count to be stored in a value...

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: count of comma separated values

    Pls, upload a sample workbook

  9. #9
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: count of comma separated values

    bujji1305,

    Can we have a workbook/worksheet with the strings in column A, and in column B the results you are looking for manually inputed by you?

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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