+ Reply to Thread
Results 1 to 7 of 7

From cell to Cells extracting data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-29-2006
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    314

    From cell to Cells extracting data

    Hi all

    I have excel report which has data in one cell but i like to break it down to different cells just below the data cell

    for example the attached has data A1 and I manually extracted this under the headers in A3 to E3 , this is just one cell's data but more cells like A1 under Colum A


    is there a macro will do this automatically? is this doable?

    kind regards
    Attached Files Attached Files

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

    Re: From cell to Cells extracting data

    Try
    Sub test()
        Dim a, x, i As Long, t As Long, m As Object
        x = Split([a1], vbLf)
        ReDim a(1 To UBound(x) + 1, 1 To 5)
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "\b(.+?)\u00A3 *([1-9]\d{0,2}(,\d{3})*\.\d{2})"
            For i = 0 To UBound(x)
                a(i + 1, 1) = Trim$(Split(x(i), "-")(0))
                x(i) = Split(x(i), "-")(1)
                For Each m In .Execute(x(i))
                    t = IIf(m.submatches(0) Like "bill*", 2, 4)
                    a(i + 1, t) = m.submatches(0)
                    a(i + 1, t + 1) = m.submatches(1)
                Next
            Next
        End With
        [a4].Resize(UBound(a, 1), UBound(a, 2)) = a
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-29-2006
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    314

    Re: From cell to Cells extracting data

    Thank you very much this works but only for A1 data,

    Is there a way we can carry on extracting A1,A2,A3,A4,.... so on, so on data, basically can any data, that Colum A has, be extracted either below cell or another sheet? As you can see new excel sheet that I attached that the data

    carries down.


    Many thanks for your help in advance.
    Attached Files Attached Files

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

    Re: From cell to Cells extracting data

    Add a worksheet named "Sheet2".
    Sub test()
        Dim a, b, e, s, i As Long, n As Long, t As Long, m As Object
        a = Sheets("sheet1").Cells(1).CurrentRegion.Resize(, 2).Value
        ReDim b(1 To UBound(a, 1) * 100, 1 To 5)
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "\b(.+?)\u00A3 *([1-9]\d{0,2}(,\d{3})*\.\d{2})"
            For i = 1 To UBound(a, 1)
                For Each e In Split(a(i, 1), vbLf)
                    If e <> "" Then
                        n = n + 1: b(n, 1) = Trim$(Split(e, "-")(0))
                        s = Split(e, "-")(1)
                        For Each m In .Execute(s)
                            t = IIf(m.submatches(0) Like "bill*", 2, 4)
                            b(n, t) = m.submatches(0)
                            b(n, t + 1) = m.submatches(1)
                        Next
                    End If
                Next
            Next
        End With
        Sheets("sheet2").[a2].Resize(n, 5) = b
    End Sub

  5. #5
    Forum Contributor
    Join Date
    08-29-2006
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    314

    Re: From cell to Cells extracting data

    That is amazing!! it is working.

    It is my fault that I realised there is no gap between each cells extraction on Sheet2 , can this also be added to distinguish the each? If you cant not to worry I will work something out.

    It is great job, I cant express my appreciation . Thank you again.
    Attached Files Attached Files

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

    Re: From cell to Cells extracting data

    Add one line in bold.
                    End If
                Next
                n = n + 1  '<--- this line
            Next
        End With

  7. #7
    Forum Contributor
    Join Date
    08-29-2006
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    314

    Re: From cell to Cells extracting data

    what can I say! I though this is never possible but you made it possible. I cant thank you enough. it is working perfectly. Respect!

+ 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. Extracting data from cells
    By javeeva in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2017, 11:55 AM
  2. Extracting data from cells
    By mrichard in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-15-2016, 03:08 PM
  3. [SOLVED] Extracting data from cells based on criteria in other cells
    By PaulMcCudden in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-21-2015, 02:56 PM
  4. [SOLVED] extracting data in one cell and making it in to two cells
    By bbhockey in forum Excel General
    Replies: 4
    Last Post: 07-10-2015, 11:43 AM
  5. Replies: 2
    Last Post: 02-25-2015, 08:26 PM
  6. Extracting VAT from a cell or group of cells
    By Duckyb in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-24-2013, 06:22 AM
  7. Replies: 6
    Last Post: 07-05-2005, 12:05 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