+ Reply to Thread
Results 1 to 3 of 3

How to determine no. of elements in a semi-colon string in Excel VBA?

  1. #1
    Registered User
    Join Date
    02-21-2007
    Posts
    20

    How to determine no. of elements in a semi-colon string in Excel VBA?

    Hello,

    I have a string in a cell

    David McUseless (7000);100;Karen SanFrancisco(190);100;

    How do I determine that there are x elements in the above string and extract each pair of string from the string?

    In the above string, there are 4 elements.

    If there are x elements, I want to divide that by 2 to get the total number of lines to insert below the active row.

    Thanks,
    Last edited by Paul; 05-02-2012 at 04:57 PM.

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

    Re: How to determine no. of elements in a semi-colon string in Excel VBA?

    If there is always a semi-colon after the last element, you could use the following formula to determine the number of elements:

    =LEN(A1)-LEN(SUBSTITUTE(A1,";",""))

    In VBA it would use Len() and Replace(), of course.

    You could then divide that by 2 to get the # of lines to insert.

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: How to determine no. of elements in a semi-colon string in Excel VBA?

    Quote Originally Posted by zwieback89 View Post
    David McUseless
    Thanks for my laugh today. Glad Paul got you worked out.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

+ 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