Hallo Stefan,
die folgenden Zeilen kannst du streichen, sie dienten nur zum Anlegen der Testdatei tesst.txt.
Open "c:\temp\tesst.txt" For Output As #1
Print #1, "10001 XY 555 XY 100 200 150"
Print #1, "XY 666 XY 100 200 150"
Print #1, "XY 777 XY 100 200 150"
Print #1, "10002 XY 555 XY 100 200 150"
Print #1, "XY 666 XY 100 200 150"
Close #1
Diese Zeile musst du umschreiben, also Pfad und Dateinamen deiner datei angeben:
Open "c:\temp\tesst.txt" For Output As #1
Gruß
Reinhard
Sub test()
Dim Zeile As Integer
Dim Textzeile As String
Dim n As Integer
Dim Prüf As Variant
Zeile = 2
Close
Open "c:\temp\tesst.txt" For Output As #1
Print #1, "10001 XY 555 XY 100 200 150"
Print #1, "XY 666 XY 100 200 150"
Print #1, "XY 777 XY 100 200 150"
Print #1, "10002 XY 555 XY 100 200 150"
Print #1, "XY 666 XY 100 200 150"
Close #1
Open "c:\temp\tesst.txt" For Input As #2
Range("a1:g65536").ClearContents
While Not EOF(2)
Input #2, Textzeile
Cells(Zeile, 1) = Textzeile
Zeile = Zeile + 1
Wend
Close #2
Range(Cells(2, 1), Cells(Zeile - 1, 1)).Select
Selection.TextToColumns Destination:=Range("a2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1))
For n = 2 To Zeile - 1
If IsNumeric(Cells(n, 1)) Then
Prüf = Cells(n, 1)
Else
Range(Cells(n, 1), Cells(n, 7)).Cut
Cells(n, 2).Select
ActiveSheet.Paste
Cells(n, 1) = Prüf
End If
Next n
Range("a1").Select
End Sub