Extract specific lines from a TXT file to an Excel Sheet

frerofrero

New Member
Joined
Jun 2, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Dear all,
I am being new to VBA (learned about the existance of VBA 2 weeks ago), and I have a question about the extraction of data from a txt file.
I have a code that extracts the data of a txt file to my excel sheet, and I wanted to know about the existence of a formula that could only extract specific lines. Example = if i want to extract lines 7, 11 and 13 is there something that could do it ? I think it is important to precise that at the begining of every line that I want to extract, there is "62C" or "62D".

For now, my code is the following :

Sub MT940Date()

Dim theDate As Date e
Dim SOF As String
Dim EOF As String
Dim FileName As String

theDate = Date
DOF = Format(theDate, "yyyymmdd")

SOF = "TEXT; \\url of my file on my computer" 'Start Of File

EOF = ".rf0" 'End Of File

FileName = SOF & DOF & EOF

MsgBox FileName

With ActiveSheet.QueryTables.Add(Connection:=FileName, Destination:=Range("$A$1"))
.Name = "Sample"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub


Thanks to everyone in advance,
Kind Regards
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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