+ Reply to Thread
Results 1 to 15 of 15

Excel VBA to get field separated by semi-colon into multiple "rows"

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Excel VBA to get field separated by semi-colon into multiple "rows"

    Good evening,
    Let me start that I can get the end result using "text to columns" then filtering the data to copy and paste what I need for every separation (long and painful and quite annoying to do with the macro recorder even with "use relative references" turned on. However, there are many people more experienced and knowledgeable out there who may have a quicker way. The Goal is so that I will be able to summarize on the "Problem Field". I have some SAS software experience where I would have possibly made 3 (my max will be more like 20) temporary tables after the text to columns then appended them back together so the field could be combined. I have not used that since 2007 and I prefer the macro so an end user can do it monthly without SAS software. I am still in the early stages of learning and executing VBA. I need to write a macro to format data as follows:

    Raw Data:

    Invoice # Customer Name Problem Field
    1 Joe Smith Radio; DVD; Wire
    2 Jane Doe Wheels; Bolts

    Resulting Data:

    Invoice # Customer Name Problem Field
    1 Joe Smith Radio
    1 Joe Smith DVD
    1 Joe Smith Wire
    2 Jane Doe Wheels
    2 Jane Doe Bolts

  2. #2
    Registered User
    Join Date
    05-28-2012
    Location
    Pittsburgh, Pa
    MS-Off Ver
    Excel 2003 - 2007 -2010
    Posts
    49

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    amyg1120,

    about this, "Excel VBA to get field separated by semi-colon into multiple "rows" ".

    It appears that you would like each row to be separated into a row of 3 "columns" not "rows"

    And Jane Doe row would result in 2 "rows" of 3 "columns" each.

    Correct>

    cplmckenzie

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"


    Hi,

    without any idea of the data location, just see Split function …

  4. #4
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Smile Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Thanks, I have no problem separating the problem field into 3 columns. My problem is getting the first two columns to repeat with each individual item broken down from the 3rd column.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"


    Once separated, it's easy ! Attach a sample workbook …

  6. #6
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Hi there,
    Thanks very much, here is the sample workbook with a tab of where I am at and a tab of where I need to be by the end of the macro. The goal is to be able to summarize based on what is told in the delimited field which is more difficult if you delimit to multiple columns. Also, we do not want to lose visibility of which items relate to which invoice #. I want to make the VBA code easy to adjust if we end up exceeding the 15 delimit max that I am planning on. If there is a way to not have a max, I'd love the info.
    Thanks,
    Amy
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"


    Destination is source worksheet or a new one ?

    Really source worksheet has delim columns ? (column C is enough for me)

    Don't copy your « 15 delimit max » …
    Last edited by Marc L; 07-30-2014 at 01:53 PM.

  8. #8
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    I'm trying to keep it all within one workbook: 1) raw data, 2) working data which is what my first tab is and then 3) results. The results will be copied and pasted by the end user into a separate workbook each month for a tracker to see how many DVDs per month, etc. So destination would be new worksheet. Raw Data has the delimited field. Working Data is where I have delimited it already. Just wanted to show that I can delimit no problem just getting the invoice information to repeat in multiple lines with each separation is the problem. I do want to skip having that max but not sure how to get there just yet. It is entirely possible that an invoice could have 16+ items even if not at this time.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"


    If I well copy, raw worksheet has only the 3 first columns, right ?
    In this case I 'll start from this sheet (just need column D be empty).

  10. #10
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Yes, you are correct

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Hi amyg1120,
    maybe so
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Thanks, that works on the sample for sure and I will try it out on my real data!

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Thumbs up Re: Excel VBA to get field separated by semi-colon into multiple "rows"


    Same way I start …

    Just insert before last End With line :
    Please Login or Register  to view this content.
    My little contribution !

  14. #14
    Registered User
    Join Date
    04-16-2013
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Hi guys,
    I have really given this a shot on my own as I want to learn and understand the code without asking for help. However, I am hitting a wall.... Here is my actual macro and the test file that I choose on the open file prompt I have within. I thought I was smart enough to adjust for my real life example but apparently not today. I'm pregnant so at least I can blame it on the baby taking my brain power. I greatly appreciate any time you spend!
    Thanks,
    Amy

    7-31-2014 4-28-16 PM.jpg

  15. #15
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Excel VBA to get field separated by semi-colon into multiple "rows"

    Hi Amy,
    Look at this line in your code
    Please Login or Register  to view this content.
    (should be Rws instead of 1)

+ 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. Macro that can merge a column of cells into one cell separated by semi colon
    By glide2131 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-25-2013, 05:23 PM
  2. Sort Names separated by semi-colon
    By her.rockstar in forum Excel General
    Replies: 2
    Last Post: 01-24-2013, 11:53 AM
  3. Excel 2010 open semi-colon separated file
    By thinksnowjob in forum Excel General
    Replies: 3
    Last Post: 01-15-2013, 08:21 PM
  4. Parse a semi-colon separated string and insert each value into individual columns
    By zwieback89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2011, 06:44 PM
  5. Replies: 2
    Last Post: 05-27-2011, 05:46 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