+ Reply to Thread
Results 1 to 12 of 12

Comma separated string element count

  1. #1
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Comma separated string element count

    I need to count how many comma separated elements are in each cell. THis is what I have so far,
    Please Login or Register  to view this content.
    The error is Method 'Range" of object'.

    Any help will be greatly appreciated.

    Thanks!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Comma separated string element count

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Comma separated string element count

    The previous code counts commas. This counts elements:

    Please Login or Register  to view this content.

    Regards, TMS

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

    Re: Comma separated string element count

    I was going to mention the "+1" TMS.

    I chose not to hide zeros here:
    Please Login or Register  to view this content.
    Or you could use a function such as the following, and then use a formula in column K:
    Please Login or Register  to view this content.
    Formula in K12 would be:

    =UOM_Count(I12)

    Fill down as many rows as you want. You can format the cells to hide zeros if you want, too. (Same would apply to the macro version.)

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

    Re: Comma separated string element count

    Of course, if you wanted to forego all code and just use native Excel functions, try:

    =LEN(I12)-LEN(SUBSTITUTE(I12,",",""))+IF(I12="",0,1)

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Comma separated string element count

    Not sure if this is how you wanted.

    This counts 5 for the data like "a,,,b,,,c,,,d,,,e,,,"

    Please Login or Register  to view this content.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Comma separated string element count

    @Paul: to be honest, the first response was just a case of "fixing" the posted code, and then attempting to replicate it but shorter/quicker. And, what it does is count the commas. Fair enough, made it do that. Then I looked again at the first sentence which says "comma separated elements" ... hence the revisit.

    And the only reason for avoiding the zeros is that my test data had more data in column E than it did in column I.

    Regards, TMS

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

    Re: Comma separated string element count

    I knew where you were coming from TMS, no worries.

    Cheers!

  9. #9
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: Comma separated string element count

    Wonderful!!!! Never expected so many responses.

    Lots of thanks to you all.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Comma separated string element count

    You're welcome.

  11. #11
    Registered User
    Join Date
    09-06-2017
    Location
    indai
    MS-Off Ver
    2013
    Posts
    38

    Re: Comma separated string element count

    Hi,
    I am new to VBA, I want to count unique comma separated names in the cells, for example- E11 to E16 there are several names separated by a comma and space & few duplicate entries, so can anyone help me to count how many unique name in the range.

    thanks
    rao

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Comma separated string element count

    @raogm2001:

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

+ 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] Dynamic COUNTIF function looking for text value in comma-separated string
    By thewhawk in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-27-2017, 06:29 PM
  2. Formula help on comma separated String data?
    By JGTExcel in forum Excel General
    Replies: 5
    Last Post: 02-10-2012, 01:05 PM
  3. Formula help on comma separated String data?
    By JGTExcel in forum Excel General
    Replies: 1
    Last Post: 02-09-2012, 03:33 AM
  4. Comma separated string
    By ESF in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2011, 06:39 AM
  5. count comma separated information
    By fjosef87 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 04-04-2010, 10:47 AM

Tags for this Thread

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