Copy String to individual columns in new worksheet

Hi I want an excel Spreadsheet to look a text file and do some formatting based on a string of text

14:42:47 : B19 1 Rod drawn/pushed successfully on Bar Tensioner
14:45:47 : B19 1 Rod drawn/pushed successfully on Bar Tensioner
14:47:47 : B19 1 Rod drawn/pushed successfully on Bar Tensioner
14:52:47 : B19 1 Rod drawn/pushed successfully on Bar Tensioner

This data is located in a worksheet called Target Period
This is how the string represents in the Column B Cells 1 to 1000

I would like to look down the column and where the value B19 appears perform the following

I want to copy the string to individual columns in a new sheet called Data

I would like to put (14:42:47 into A1) (: into B1) (B19 into C1) and (1 into D1) and the rest of the string into E1

There might be up to 10 lines of other values in the data between the B19 values however would like the to copy into the new Data sheet on incremental rows. i.e. first instance row 1 second instance row 2
IT SSMAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try

Sub Macro1()
For Each c In Range(Range("B1"), Range("B" & Cells.Rows.Count).End(xlUp))
    If c.Value Like "*B19*" Then
        arrC = Split(c, " ")
        If Evaluate("=ISERROR('Data'!A1)") Then
            Set newSh = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count))
            newSh.Name = "Data"
            Rw = 1

            Set newSh = ActiveWorkbook.Sheets("Data")
            Rw = newSh.Range("A" & Cells.Rows.Count).End(xlUp).Row + 1
        End If
        newSh.Range("A" & Rw) = arrC(0)
        newSh.Range("B" & Rw) = arrC(1)
        newSh.Range("C" & Rw) = arrC(2)
        newSh.Range("D" & Rw) = arrC(3)
        newSh.Range("E" & Rw) = Mid(c, Len(arrC(0) & " " & arrC(1) & " " & arrC(2) & " " & arrC(3)) + 2)
    End If
End Sub

Open in new window



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try this to see if you get the desired output.....
The following code is based on your sample workbook which you attached in your previous question.
Please change the Sheet Names in the code where I have commented in the code.
Sub ExtractData()
Dim Sws As Worksheet, Dws As Worksheet
Dim Slr As Long, r As Long, i As Long, j As Long, c As Long
Dim str() As String, Constr As String
Set Sws = Sheets("Source")      'Source Sheet
Set Dws = Sheets("Data")         'Destination Sheet
Slr = Sws.Cells(Rows.Count, 1).End(xlUp).Row
r = 1
For i = 1 To Slr
    If InStr(Sws.Cells(i, 1), "B19") > 0 Then
        str() = Split(Sws.Cells(i, 1), " ")
        c = 1
        For j = 0 To UBound(str)
            If c <= 4 Then
            Dws.Cells(r, c) = str(j)
                Constr = Constr & " " & str(j)
                Dws.Cells(r, 5) = Trim(Constr)
            End If
            c = c + 1
        Next j
        Erase str()
        r = r + 1
    End If
Next i
End Sub

Open in new window

In the attached workbook, you may click the button Click Here to run the code.
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.