Results 1 to 22 of 22

split multiple semicolon separated values into new rows for multiple columns

Threaded View

  1. #1
    Registered User
    Join Date
    01-02-2014
    Location
    Tri-State Area, USA
    MS-Off Ver
    Excel 2010
    Posts
    26

    split multiple semicolon separated values into new rows for multiple columns

    Hello,

    I currently have data that reads like the attached. I've gotten quite far cobbling some code together but for the life of me I just can't figure out this last moderation. Can somebody help adjust my code so that the semicolon separated values are split in columns B & C simultaneously and create corresponding rows below with the original rows data in the remaining columns (A, D, E, F, G) ?

    The workbook attached contains three tabs. Raw is the raw datam Current Output is the result of my current macro which is also included in the workbook, and Desired Output is what I want it to look like after the macro. Any help would be greatly appreciated, thank you!


    Code:

    Sub cobble()
    
    Dim rng As Range
    Dim r As Long
    Dim arrParts() As String
    Dim partNum As Long
    Dim X As Range
    
     Sheets("Raw").Select
        Cells.Select
        Selection.Copy
        Sheets("Current Output").Select
        ActiveSheet.Paste
        Range("A1").Select
        
        
         Sheets("Current Output").Select
    
    
    'step 2
    Set rng = Range("A1:G13876")
    
    r = 2
    Do While r <= rng.Rows.Count
        'Split the value in column B (2) by commas, store in array
        arrParts = Split(rng(r, 2).Value, ";")
    
        
        'If there's more than one item in the array, add new lines
        
        If UBound(arrParts) >= 1 Then
            rng(r, 2).Value = arrParts(0)
            
                
        
       
            'Iterate over the items in the array
            
            For partNum = 1 To UBound(arrParts)
             'For partNum1 = 1 To UBound(arrParts1)
      
            
                'Insert a new row '
                'increment the row counter variable
                
                r = r + 1
                rng.Rows(r).Insert Shift:=xlDown
    
                'Copy the row above '
                
                rng.Rows(r).Value = rng.Rows(r - 1).Value
    
                'update the part number in the new row '
                
                rng(r, 2).Value = Trim(arrParts(partNum))
                
    
                'resize our range variable as needed
                
                Set rng = rng.Resize(rng.Rows.Count + 1, rng.Columns.Count)
    
            Next
    
        End If
    cobble.xlsm
        
    'increment the row counter variable
    
    r = r + 1
    Loop
    
    
    End Sub
    Last edited by FDibbins; 01-02-2014 at 06:21 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Split multiple values in a cell to multiple rows
    By karmithr in forum Excel General
    Replies: 2
    Last Post: 03-04-2013, 08:34 PM
  2. Import multiple semicolon separated csv files
    By Ivodv in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-07-2012, 08:17 AM
  3. CSV file with two columns multiple values separated by pipe. Need to Combine
    By nikythebest in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-01-2012, 04:30 AM
  4. Best way to parse colums and rows w/ multiple values separated by comma?
    By Sutukh19 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-28-2009, 04:37 AM
  5. Column with semicolon-separated values
    By nsv in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2006, 08:22 AM

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