Need Help Parsing a Record Layout

perryjasonc

New Member
Joined
Nov 20, 2017
Messages
3
I receive a record every day that has several sequences. Each sequence is a row followed by a string that is all in the same column. I need Excel to break apart these sequences into certain lengths that represent data such as names and account numbers. Below is an example of what the raw data looks like.

[TABLE="width: 64"]
<tbody>[TR]
[TD]F51010058 080705P2031234567890 12345678901123456789012345 123456789012345
[TABLE="width: 64"]
<tbody>[TR]
[TD]F51020058SCHOLARSCHOICECOLLEGESVGSPRGM JANEDOE
[TABLE="width: 64"]
<tbody>[TR]
[TD]F51030058FBOJOHNDOE 12345CHRISTMASDR
[TABLE="width: 64"]
<tbody>[TR]
[TD]F51040058 NORTHPOLE CO021

But I can't just simply to text to columns, because the data in each row I need to parse isn't the same length.

Does anyone know how to make a macro that can identify the first 5 characters in the string, then use a MID formula or something like that to cut up the rest of the string and move certain data elements to a new sheet in a specific column?

Sorry, I know that is vague but I am in a rush. Will clarify more if needed.[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
[/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Welcome to the Board!

Note that "Text to Columns" can delimit data in multiple ways:
- by a defined delimiter (like comma, space, tab, etc)
- by Fixed Width

Based on your data, I am not quite clear on how it should determine where/how things should be split up.
Could you post a few examples, along with the expected results (and explain exactly how you got to those expected results in your examples)?
I think we need to see/understand the exact logic you are using here.
 
Upvote 0
Thank you for taking the time to reply.

Now that I am not rushing around, I've thought about my problem in a different way. What would be more helpful to me is way to move a row to the one above it if it starts with a certain value. Then do that over and over again. My data is several hundred thousand rows.

F51010058 080705P2031234567890
F51020058SCHOLARSCHOICECOLLEGESVGSPRGM
F51030058FBOJOHNDOE
F51010058 080705P2031234567890
F51020058SCHOLARSCHOICECOLLEGESVGSPRGM
F51030058FBOJOHNDOE

If my data looks like what I have above, I would like for excel to be able to identify that the second row starts with "F5102" then add that to the end of the row above it that starts with "F5101". Then do that for everything that starts with "F51##" until it finds an "F5101" again. Then I can use Text to Columns after that the break apart the string as needed.
 
Upvote 0
Re: Code to Cut and Paste Data to the Row Above

As you haven't said where your data is located I've used col A starting in A1.
I've also assumed that the first value (A1 in this case) will start with F5101
Code:
Sub ConcatRws()

    Dim Cl As Range
    Dim Rng As Range
    
    For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
        If Left(Cl.Value, 5) = "F5101" Then
            Set Rng = Cl
        Else
            Rng.Value = Rng.Value & [COLOR=#ff0000]""[/COLOR] & Cl.Value
            Cl.ClearContents
        End If
    Next Cl
    [COLOR=#0000ff]Columns(1).SpecialCells(xlBlanks).EntireRow.Delete[/COLOR]
    
End Sub
If you need a delimiter added, then added it between the quotes in red.
At the moment this will delete the entire row where data has been removed, if you don't want that to happen, then remove the line in blue.
 
Upvote 0
Sorry, I have been away for a few days.

Try this:
Code:
Sub MyCombineMacro()

    Dim lastRow As Long
    Dim r As Long
    Dim cell As Range

    Application.ScreenUpdating = False

'   Find last row with data in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows, starting at the bottom
    For r = lastRow To 2 Step -1
        Set cell = Cells(r, "A")
        If Left(cell, 5) <> "F5101" Then
            cell.Offset(-1, 0) = cell.Offset(-1, 0) & Mid(cell, 10)
            Rows(r).Delete
        End If
    Next r
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
If you have less than 65,000 rows of data, then here is another macro that you can consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub MyCombineMacro()
  Dim Grouped As Variant
  Grouped = Application.Transpose(Split(Mid(Join(Application.Transpose(Evaluate(Replace("(IF(LEFT(@,5)=""F5101"",""|""&@,MID(@,10,LEN(@))))", "@", "A1:A" & Cells(Rows.Count, "A").End(xlUp).Row))), ""), 2), "|"))
  Range("B1").Resize(UBound(Grouped)) = Grouped
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top