Results 1 to 7 of 7

Need A Macro that takes comma delimited values in select columns and seperates them to row

Threaded View

TroyBehmer Need A Macro that takes comma... 01-15-2015, 03:40 PM
protonLeah Re: Need A Macro that takes... 01-18-2015, 10:04 PM
protonLeah Re: Need A Macro that takes... 01-18-2015, 10:58 PM
TroyBehmer Re: Need A Macro that takes... 01-19-2015, 11:45 AM
dolphino Re: Need A Macro that takes... 01-19-2015, 02:12 AM
TroyBehmer Re: Need A Macro that takes... 01-19-2015, 10:55 AM
protonLeah Re: Need A Macro that takes... 01-19-2015, 08:16 PM
  1. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: Need A Macro that takes comma delimited values in select columns and seperates them to

    Assume columns C & E shall not be split; B, D & F are split

    Option Explicit
    Sub Split_BDF()
    
        Dim ArrPtr      As Long, _
            RecCount    As Long, _
            MaxBD       As Long, _
            DestRow     As Long, _
            Split_B()   As String, _
            Split_D()   As String, _
            Split_F()   As String, _
            TestCell    As Variant, _
            DEST        As Worksheet, _
            SOURCE      As Worksheet
    
        Set SOURCE = Sheets("Sheet1")
        Application.DisplayAlerts = False
        On Error Resume Next
        Sheets("Workspace").Delete
        On Error GoTo 0
        
        Sheets.Add after:=Sheets(Sheets.Count)
        ActiveSheet.Name = "WorkSpace"
        Set DEST = ActiveSheet
        Application.DisplayAlerts = True
        
        With SOURCE
            RecCount = .Cells(.Rows.Count, "A").End(xlUp).Row
    
            For Each TestCell In .Range("A1:A" & RecCount)
                'columns B, D & F shall be split
                Split_B = Split(TestCell.Offset(columnoffset:=1).Value, ",")
                Split_D = Split(TestCell.Offset(columnoffset:=3).Value, ",")
                Split_F = Split(TestCell.Offset(columnoffset:=5).Value, ",")
                
                'get the larger upper bound of the two arrays
                MaxBD = WorksheetFunction.Max(UBound(Split_B), UBound(Split_D), UBound(Split_F))
                
                'make both arrays same size
                'the previously smaller one will have a blank last element
                
                ReDim Preserve Split_B(0 To MaxBD)
                ReDim Preserve Split_D(0 To MaxBD)
                ReDim Preserve Split_F(0 To MaxBD)
                
                For ArrPtr = 0 To MaxBD
                    DestRow = DestRow + 1
                    
                    'write column A, C & E once only for each group
                    If ArrPtr = 0 Then
                        DEST.Cells(DestRow, "A").Value = TestCell.Value
                        DEST.Cells(DestRow, "C").Value = TestCell.Offset(columnoffset:=2).Value
                        DEST.Cells(DestRow, "E").Value = TestCell.Offset(columnoffset:=4).Value
                    End If
                    
                    'write all array elements
                    DEST.Cells(DestRow, "B").Value = Split_B(ArrPtr)
                    DEST.Cells(DestRow, "D").Value = Split_D(ArrPtr)
                    DEST.Cells(DestRow, "F").Value = Split_F(ArrPtr)
                Next ArrPtr
            Next TestCell
        End With     'SOURCE
    End Sub
    Last edited by protonLeah; 01-21-2015 at 12:50 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Separate comma-delimited values to rows
    By sporto in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-22-2013, 10:06 AM
  2. Splitting comma delimited numbers into new columns
    By salmansohail in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2010, 07:00 PM
  3. SUM of values in a comma delimited cell
    By Danexcel in forum Excel General
    Replies: 18
    Last Post: 01-15-2010, 10:59 AM
  4. Splitting comma delimited numbers into new columns
    By Cicada in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-23-2009, 07:30 PM
  5. separating values in comma delimited cells
    By JChandler22 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2008, 06:31 PM

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