I have a vba-code to import multiple txt-files into excel. Every txt-file contains a few lines starting with #
. This lines I would like to skip and begin the import at the first line without #
.
The code I am using to import the files is the following:
Sub Import_Text_Files()
Dim sPath As String
Dim oPath, oFile, oFSO As Object
Dim r, iRow As Long
Dim wbImportFile As Workbook
Dim wsDestination As Worksheet
sPath = "C:\txt-files\"
Set wsDestination = ThisWorkbook.Sheets("Daten")
i = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oPath = oFSO.GetFolder(sPath)
Application.ScreenUpdating = False
For Each oFile In oPath.Files
r = 4
If LCase(Right(oFile.Name, 4)) = ".txt" Then
Workbooks.OpenText fileName:=oFile.Path, Origin:=65001, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Set wbImportFile = ActiveWorkbook
For iRow = 1 To wbImportFile.Sheets(1).UsedRange.Rows.Count
wbImportFile.Sheets(1).UsedRange.Rows(iRow).Copy wsDestination.Cells(r, i)
r = r + 1
End If
Next iRow
wbImportFile.Close False
Set wbImportFile = Nothing
End If
i = i + 7
Next oFile
End Sub
I tried with INSTR
but it didn't work.
Can anybody help me?