Looping a one row occurence through rows

hgus393

New Member
Joined
Mar 22, 2011
Messages
29
Hi all,

Sorry for the title. My problem is the following. I have a txt file that i read into excel. The file looks like this..an excerpt:
01ABBBBBB
02Hello
0320110906 1JamesSmith

0520110905+004800000000+004865693590+0009996001601
.
.
.

The row that starts with 05 is the row that contain all the data. That row goes on for 10 000 entries then it starts again with the row 03 chaning to say for example 0320110906 1AdamJones

I can capture the data rows, ie 05 rows, no problems. But how can I loop the row 03 ie JamesSmith and put this beside the data rows 05 and then loop this until the next occurence of a 03 row and the loop the new 03 row beside the data row 05....etc..

This is what I have now:
Code:
Sub TxtfileImport()
    Dim objFso
    Dim objTF
    Dim i As Long
    Dim X()
    Dim ArrLines, aLine
    Dim InFile As String
    Dim z
 
    With Application
        .ScreenUpdating = False
        .Application.EnableEvents = False
    End With
    InFile = "C:\temp\Data.txt"
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objTF = objFso.OpenTextFile(InFile)
    ArrLines = Split(objTF.ReadAll, vbCrLf)
    ReDim X(1 To UBound(ArrLines, 1) + 1, 1 To 2)
 
   For Each aLine In ArrLines
 
           If Left$(aLine, 2) = "05" Then
            i = i + 1
            X(i, 1) = Mid$(aLine, 3, 10) 'gets date
            X(i, 2) = Mid$(aLine, 37, 14) ' gets values
 
 
     End If
    Next
    ThisWorkbook.Sheets("Sheet1").[a1].Resize(UBound(X, 1), UBound(X, 2)) = X
 
    With Application
        .ScreenUpdating = True
        .Application.EnableEvents = True
    End With
    objTF.Close
    Set objTF = Nothing
End Sub
Cheers
Rob
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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