+ Reply to Thread
Results 1 to 5 of 5

VB to split and repeat rows based on cell values

  1. #1
    Registered User
    Join Date
    05-14-2010
    Location
    Tennessee
    MS-Off Ver
    Excel 2007
    Posts
    4

    VB to split and repeat rows based on cell values

    Hello all,
    I am somewhat new to VB and wish to ask advice. I'm attempting to automate a process which is currently done manually. I have a Excel file which contians columns CLIENT_ID NAME PURCHASE_TYPE DATE_ADDED, MATERIAL . In the MATERIAL column, it is possible for multiple material items to be present and separated by commas and spaces. Occasionally, a comma will be the last value present in the column. I have been tasked with finding rows with multiple material occurances, and splitting the occurances into new rows while copying the data which exists in the current row of CLIENT_ID NAME PURCHASE_TYPE DATE_ADDED. I will try and visuallize below...

    CLIENT_ID NAME PURCHASE_TYPE DATE_ADDED MATERIAL
    1 N1 E 1/1/2010 A, B, C
    2 N2 F 1/1/2010 A,
    3 N3 G 1/1/2010 B
    4 N4 E 1/1/2010 A, B, C
    ...and so on...

    solution should look like...

    CLIENT_ID NAME PURCHASE_TYPE DATE_ADDED MATERIAL
    1 N1 E 1/1/2010 A
    1 N1 E 1/1/2010 B
    1 N1 E 1/1/2010 C
    2 N2 F 1/1/2010 A
    3 N3 G 1/1/2010 B
    4 N4 E 1/1/2010 A
    4 N4 E 1/1/2010 B
    4 N4 E 1/1/2010 C


    Thank you in advance for your cooperation.
    Last edited by rgjohnson; 05-14-2010 at 06:57 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB to split and repeat rows based on cell values

    Hello rgjohnson,

    Welcome to the Forum!

    The attached workbook has your example data and the macro below added to it. A button on "Sheet2" will run the macro.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VB to split and repeat rows based on cell values

    The macro posted here does this:
    In the code, just change the COL = 2 to COL = 4 if it's column D you want split out. All the other columns will be duplicated. There's a sample workbook on that page, too.
    Last edited by JBeaucaire; 05-14-2010 at 05:31 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VB to split and repeat rows based on cell values

    Hello JB,

    As your teacher told you in school, please show your work. It is for the benefit of the whole class.
    Last edited by Leith Ross; 05-14-2010 at 06:25 PM.

  5. #5
    Registered User
    Join Date
    05-14-2010
    Location
    Tennessee
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VB to split and repeat rows based on cell values

    Thanks to everyone...I am awed by your knowledge!

+ 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