AW: TXT-Datei importieren / Zellenformat
28.11.2020 01:36:18
Tino
Hallo,
hier mal eine Variante zum testen.
Die Textdatei wird über ein Dialog erfasst.
Sub ImportTxT()
Dim sFile$, sInhalt$, varInhalt, varRowTxT, ArAusgabe()
Dim c&, r&, F%
'Import ab Zeile
Const AbZeile& = 9
'Auswahl Textfile
sFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If sFile = CStr(False) Then Exit Sub
'Textfile einlesen
F = FreeFile
Open sFile For Binary As #F
sInhalt = Space$(LOF(F))
Get #F, , sInhalt
Close
'Text in Zeilen aufteilen
varInhalt = Split(sInhalt, vbCrLf)
If UBound(varInhalt) "" Then
'Text-Zahlen in Zahl wandeln
If IsNumeric(varRowTxT(c)) Then
ArAusgabe(r - 7, c + 1) = varRowTxT(c) * 1
Else
ArAusgabe(r - 7, c + 1) = varRowTxT(c)
End If
End If
Next
Next
Application.ScreenUpdating = False
Application.EnableEvents = False
With Tabelle1 'Ausgabe Tabelle
.Rows(6).ClearContents 'Inhalt löschen
.Range("A7", .Cells(.Rows.Count, 1)).EntireRow.Delete 'alles löschen
With .Range("A6").Resize(UBound(ArAusgabe), UBound(ArAusgabe, 2))
.Value = ArAusgabe
If .Rows.Count > 1 Then
.Rows(1).Copy
.Rows(2).Resize(.Rows.Count - 1).PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End If
End With
Application.Goto .Cells(1, 1), True
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
MsgBox "Import abgeschlossen!", vbInformation
End Sub
Gruß Tino