+ Reply to Thread
Results 1 to 22 of 22

split multiple semicolon separated values into new rows for multiple columns

Hybrid View

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

    Re: split multiple semicolon separated values into new rows for multiple columns

    apologies I am getting a subscript out of range error when I run the code. Since I have some cases where column 2 will be blank and column 3 populated and vice versa (in any case at least one of those columns will always be populated) I suppose this might be the cause of the error. Is there a quick line or two that might account for this case?

    This is the line where I am getting the error:

    Cells(W, 3).Value = Trim(SP3(IIf(N > U3, U3, N)))

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

    Lightbulb Try this :

    Sub SplitColumns()
        Dim SP2$(), SP3$()
                                AR = [A1].CurrentRegion.Value
                                U& = UBound(AR, 2):  If U < 3 Then Exit Sub
        Application.ScreenUpdating = False
                                W& = 1
        For R& = 2 To UBound(AR)
            SP2 = Split(AR(R, 2), ";")
            SP3 = Split(AR(R, 3), ";")
            U3& = UBound(SP3)
    
            For N& = 0 To UBound(SP2)
                                W = W + 1
                Cells(W, 1).Value = AR(R, 1)
                Cells(W, 2).Value = Trim(SP2(N))
                If U3 < 0 Then T$ = "" Else T = Trim(SP3(IIf(N > U3, U3, N)))
                Cells(W, 3).Value = T
                If U > 3 Then For C& = 4 To U: Cells(W, C).Value = AR(R, C): Next C
            Next N
        Next R
    
        R = W - 1
    
        For C = 1 To U
            With Cells(2, C)
                .Resize(R).NumberFormat = .NumberFormat
            End With
        Next
    
        Application.ScreenUpdating = True
        End
    End Sub

+ 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. 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