Remove Headers

  • Thread starter Thread starter Hilton
  • Start date Start date
H

Hilton

I have a 125 files combined into 1 file. As a result the combined file has
headers all over. The data line starts with a "*" and the headers start with
a "!". How do I step through the file and delete all the headers except the
1st one? Please help.

Thanks
Hilton
 
Hilton,

Can you sort your whole file by the field starting with ! and then delete
out all the repeating headers except for one?
 
Can you select the column with the headers and then apply
data|Filter|autofilter.

Then filter to show those rows that start with !

Exclude the first row and select the rest. Then delete those visible rows.
 
Apologies, it is a text file and too big too fit into excel. I probably
require a VBA macro.
 
Or some other text editor.

But if you want to try a macro...

Option Explicit
Sub testme01()

Dim TextLine As String
Dim FirstExPt As Boolean
Dim KeepThisRecord As Boolean
Dim iRecCount As Long
Dim oRecCount As Long

'my test files
Open "c:\my documents\excel\book4.txt" For Input As #1
Open "c:\my documents\excel\book4.txt.out" For Output As #2

iRecCount = 0
oRecCount = 0
FirstExPt = True
Do While Not EOF(1)
Line Input #1, TextLine
iRecCount = iRecCount + 1
KeepThisRecord = True
If Left(TextLine, 1) = "!" Then
If FirstExPt = True Then
FirstExPt = False
Else
KeepThisRecord = False
End If
End If

If KeepThisRecord = True Then
Print #2, TextLine
oRecCount = oRecCount + 1
End If
Loop

Close #1
Close #2

MsgBox "Recs In: " & iRecCount & vbLf & "Recs Out: " & oRecCount

End Sub

Change the file names/locations to match
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top