Copy data from one cell into single cells

Posted on 2012-08-30
Last Modified: 2012-08-30
Hello Experts,

I have a macro kindly written by byundt which searches for certain data and copies it to another worksheet.  For some reason the macro will not copy the data from the last part of the data from the cell.

I have attached an example of the raw data and the macro I use to extract the relevant data.

I hope you can help.

Question by:infosec36
    LVL 18

    Accepted Solution


    Try this

    Sub kTest()
        Dim ka, k(), i As Long, H, m As Long
        Dim dic As Object, x, y, j As Long
        ka = Worksheets("Raw Data").Range("a1").CurrentRegion.Value2
        H = Worksheets("Format").Range("a1").CurrentRegion.Rows(1).Value2
        ReDim k(1 To UBound(ka, 1), 1 To UBound(H, 2))
        Set dic = CreateObject("scripting.dictionary")
            dic.comparemode = 1
        For i = 1 To UBound(H, 2)
            dic.Item(Trim$(H(1, i))) = i
        For i = 1 To UBound(ka, 1)
            x = Split(ka(i, 1), vbLf)
            For m = 0 To UBound(x)
                If InStr(1, x(m), ":") Then
                    y = Split(x(m), ":")
                    If dic.exists(Trim$(y(0)) & ":") Then
                        k(i, dic.Item(Trim$(y(0)) & ":")) = y(1)
                    End If
                End If
        Worksheets("Format").Range("a2").Resize(UBound(k, 1), dic.Count) = k
    End Sub

    Open in new window


    Author Closing Comment

    Works perfectly, thank you.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Sometimes we don't want to show zeros in our Excel spreadsheets. This is sometimes most evident in our charts. Look at the chart below, all the zero values are visible. I think that all will agree with the fact that zero values are not looking nice …
    Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
    This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now