Re: Textdateien Importieren und Filtern
15.01.2003 11:02:23
Nepumuk
Hallo Rene,
den Pfad zu den Textdateien in der Variablen Pfad musst du noch anpassen.
dein Programm:Option Explicit
Public Sub Textimport()
Dim HFile As Integer, Pfad As String, Datei As String, Text As String
Dim Zeile As Long, Spalte As Integer, Blaetter As Integer, index As Long
Dim Name_neu As String, Zeile_neu As Long
With Application
.ScreenUpdating = False
Blaetter = .SheetsInNewWorkbook
.SheetsInNewWorkbook = 1
Workbooks.Add
Name_neu = ActiveWorkbook.Name
.SheetsInNewWorkbook = Blaetter
End With
ThisWorkbook.Activate
HFile = FreeFile()
Pfad = "D:\Eigene Dateien\Test\" 'hier den Pfad anpassen!
Datei = Dir(Pfad & "*.txt")
Do Until Datei = ""
Cells.Clear
Zeile = 0
Open Pfad & Datei For Input As HFile
Do Until EOF(HFile)
Input #HFile, Text
Zeile = Zeile + 1
Spalte = 0
If Right(Text, 1) <> ";" Then Text = Text & ";"
Do Until Text = ""
Spalte = Spalte + 1
Cells(Zeile, Spalte) = Mid(Text, 1, InStr(1, Text, ";") - 1)
Text = Mid(Text, InStr(1, Text, ";") + 1)
Loop
Loop
Close
For index = 1 To Zeile
If UCase(Cells(index, 5) = "G") Or UCase(Cells(index, 5) = "U") Then
Zeile_neu = Zeile_neu + 1
Rows(index).Copy Workbooks(Name_neu).Sheets(1).Rows(Zeile_neu)
End If
Next index
Datei = Dir
Loop
Workbooks(Name_neu).Sheets(1).Cells.Columns.AutoFit
ThisWorkbook.Close False
End Sub
Gruß
Nepumuk