+ Reply to Thread
Results 1 to 8 of 8

Split Delimited nth Data into New Rows/columns

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-04-2016
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    225

    Split Delimited nth Data into New Rows/columns

    Hello All

    i have made sample, in sheet 1 is the data and i want result like in next sheet,(i made limited result as per sheet 1 it will be more) & next sheet also generate with code.!!


    Adeel
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Split Delimited nth Data into New Rows/columns

    Sub test()
        Dim a, b, i As Long, m, n As Long, ttl As Double
        a = Sheets("sheet1").Cells(1).CurrentRegion.Value
        ReDim b(1 To Rows.Count, 1 To 3)
        With CreateObject("VBScript.RegExp")
            .Global = True: .MultiLine = True
            For i = 1 To UBound(a, 1)
                .Pattern = "^ *(\d+)[\r\n]+(.*[\r\n]+){2} *(\d{2}/\d{2}/\d{4})"
                If .test(a(i, 2)) Then
                    n = n + 1: b(n, 1) = a(i, 1)
                    For Each m In .Execute(a(i, 2))
                        n = n + 1
                        b(n, 2) = m.submatches(2)
                        b(n, 3) = Val(m.submatches(0))
                        ttl = ttl + b(n, 3)
                    Next
                    n = n + 1: b(n, 1) = "Ttl"
                    b(n, 3) = ttl: ttl = 0: n = n + 1
                End If
            Next
        End With
        With Sheets("sheet2").Cells(1).Resize(, 3)
            .Value = [{"#'S","Date","Payments"}]
            .Rows(2).Resize(n).Value = b
            .EntireColumn.AutoFit
        End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-04-2016
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    225

    Re: Split Delimited nth Data into New Rows/columns

    thanks a lot Jindon, this is great outclass staff
    little change that next sheet auto generate with result please

    Adeel

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Split Delimited nth Data into New Rows/columns

    Change
        With Sheets("sheet2").Cells(1).Resize(, 3)
    to
        With Sheets.Add.Cells(1).Resize(, 3)

  5. #5
    Forum Contributor
    Join Date
    08-04-2016
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    225

    Re: Split Delimited nth Data into New Rows/columns

    thanks a lot Jindon, you are champ

  6. #6
    Forum Contributor
    Join Date
    08-04-2016
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    225

    Re: Split Delimited nth Data into New Rows/columns

    Hi jindon
    i found some issue that code isn't pick amount in negative and also which has dots like 983.58, please review sheet 4 yellow highlighted

    Adeel
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Split Delimited nth Data into New Rows/columns

    Sub test()
        Dim a, b, i As Long, m, n As Long, ttl As Double
        a = Sheets("sheet1").Cells(1).CurrentRegion.Value
        ReDim b(1 To Rows.Count, 1 To 3)
        With CreateObject("VBScript.RegExp")
            .Global = True: .MultiLine = True
            For i = 1 To UBound(a, 1)
                .Pattern = "^ *(-?\d+(\.\d+)?)[\r\n]+(.*[\r\n]+){2} *(\d{2})/(\d{2})/(\d{4})"
                If .test(a(i, 2)) Then
                    n = n + 1: b(n, 1) = a(i, 1)
                    For Each m In .Execute(a(i, 2))
                        n = n + 1
                        b(n, 2) = DateSerial(m.submatches(5), _
                            m.submatches(4), m.submatches(3))
                        b(n, 3) = Val(m.submatches(0))
                        ttl = ttl + b(n, 3)
                    Next
                    n = n + 1: b(n, 1) = "Ttl"
                    b(n, 3) = ttl: ttl = 0: n = n + 1
                End If
            Next
        End With
        With Sheets.Add.Cells(1).Resize(, 3)
            .Value = [{"#'S","Date","Payments"}]
            .Rows(2).Resize(n).Value = b
            .EntireColumn.AutoFit
        End With
    End Sub
    Edit: Just realized the dates, if they need to be serial dates.
    Last edited by jindon; 11-28-2018 at 09:45 AM.

  8. #8
    Forum Contributor
    Join Date
    08-04-2016
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    225

    Re: Split Delimited nth Data into New Rows/columns

    thanks a lot Jindon, now its working fine thank you so much

+ 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 data into multiple columns and rows based on specific string
    By qiyusi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-13-2018, 02:01 PM
  2. [SOLVED] Transpose split data from rows to columns
    By sawan202 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-06-2018, 08:38 PM
  3. Vba code to split data with delimited "," in separate rows
    By gaikwad.mm@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-26-2017, 02:26 AM
  4. Delimited Data - Columns and Rows
    By Arch88 in forum Excel General
    Replies: 1
    Last Post: 06-01-2016, 07:11 AM
  5. [SOLVED] Multi columns of delimited data into rows
    By DWTK in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-18-2013, 11:18 AM
  6. Split forward slah delimited column to rows
    By Abu-Dina in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2012, 05:50 AM
  7. Split one row of data to columns and rows
    By A7md in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-12-2011, 05:52 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