hallo!
habe folgendes problem. ich muss eine textdatei mittels commandbutton in ein excel sheet einlesen, was ich folgendermaßen gemacht hab:
Private Sub CommandButton2_Click()
Dim ws As Worksheet
Dim ws1 As Worksheet
Set ws = Worksheets("Tabelle1")
Set ws1 = Worksheets("Tabelle2")
ws.Range("A1", "F1").Copy Destination:=ws1.Range("A1", "F1")
Application.CutCopyMode = False
Tabelle1.Range("A1", "D3") = Tabelle1.Range("A1", "D3")
Dim strDateiname As String
Dim wksZ As Worksheet
Dim wkbQ As Workbook
Dim lngLastRowA As Long
Dim lngLastRowB As Long
Dim lngLastRowAT As Long
Dim lngLastRowAU As Long
Dim intZaehler As Integer
Dim Lastcol As Long
Dim i As Integer
On Error GoTo Datenuebernahme_Error
strDateiname = Application.GetOpenFilename("test (.txt), *.txt")
If Dir(strDateiname) = "" Then Exit Sub
Application.ScreenUpdating = False
Set wkbQ = Workbooks.Open(strDateiname)
Set wksZ = ThisWorkbook.Sheets(1)
lngLastRowA = wkbQ.Sheets(1).Cells(65536, 1).End(xlUp).Row
lngLastRowB = wkbQ.Sheets(1).Cells(65536, 2).End(xlUp).Row
lngLastRowAT = wkbQ.Sheets(1).Cells(65536, 46).End(xlUp).Row
lngLastRowAU = wkbQ.Sheets(1).Cells(65536, 47).End(xlUp).Row
Lastcol = wkbQ.Sheets(1).Cells(65536, 47).End(xlUp).Column
For i = 1 To lngLastRowA
For intZaehler = 1 To 47
wksZ.Cells(i, intZaehler) = wkbQ.Sheets(1).Cells(i, intZaehler)
Next intZaehler
Next i
wkbQ.Close False
Set wkbQ = Nothing
Set wksZ = Nothing
Application.ScreenUpdating = True
On Error GoTo 0
Exit Sub
Datenuebernahme_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") im Makro Datenuebernahme in Modul1"
wkbQ.Close False
Set wkbQ = Nothing
Set wksZ = Nothing
Application.ScreenUpdating = True
End Sub
das funktioniert soweit ohne probleme. nur hab ich dann das problem dass die textdatei so aussieht:
0.02534 | 0.00000 | 16.63433 | 15.63434 | 0.00000 | 0.65755 |
dadurch schreibt mir excel alles in eine zelle. ich sollte aber bei jedem | eine neue zelle haben.
kann mir jemand helfen, wie ich das in mein code hineinbekomme?
dann hab ich noch eine frage, wie kann ich das machen, dass es immer die gleiche textdatei einliest? ich glaub das liegt an dieser zeile:
strDateiname = Application.GetOpenFilename("test (.txt), *.txt")
danke greetz
mäki
|