ich habe ein Problem: Meine Aufgabe lautet Daten aus verschiedenen Zellen in einen String mit 128 Zeichen zu exportieren. Die Felder haben unterschiedliche Feldlängen.
Problem dabei ist, das auch die Zeilen nicht alle gleich sind, ein Beispiel
Leerzeichen stehen immer für eine neue Spalte
A3
16631 00000000000000000
40 23603 735 8 7701376510 3564 Test 00020 00020050 0000 345006 000000000000 000000401000
40 23603 735 8 7701376510 3564 Test 00020 00020050 0000 345006 000000000000 000000401000
40 23603 735 8 7701376510 3565 Test 00020 00020050 0000 345006 000000000000 000000401000
3 5081935 2802130000007 575800000000000000000 000000000000000000 00000000757580000000143
Die Zeilen die Fett markiert (ab Zeile zwei) sind können mal nur eine Zeile oder aber auch mal 200 Zeilen sein. Beginnen aber immer mit 40. Die letzte Zeile beinhaltet in A immer die Zahl 3
Was ich schon gefunden habe :
Sub Export()
Dim strTmp As String, strText As String, strFile As String, strTmp1 As String
Dim intRow As Integer, intCol As Integer, intRow1 As Integer, intCol1 As Integer
Dim iRowL As Integer, iRow As Integer
strFile = InputBox("Dateiname:", , "c:\excel\test.txt")
If strFile = "" Then Exit Sub
Open strFile For Output As #1
For intRow1 = 3 To 3
For intCol1 = 1 To ActiveSheet.UsedRange.Columns.Count
strText = Cells(intRow1, intCol1).Text
strText = WorksheetFunction.Substitute(strText, "ö", "")
Select Case intCol1
Case 1: strTmp = strTmp & strText & String(5 - Len(strText), " ")
Case 2: strTmp = strTmp & strText & String(123 - Len(strText), " ")
End Select
Next intCol1
Print #1, strTmp1
strTmp1 = ""
Next intRow1
'For intRow = 4 To 20
iRow = Cells(Rows.Count, 1).End(xlUp).Row
For intRow = 4 To iRow
ActiveSheet.UsedRange.Rows.Count
For intCol = 1 To ActiveSheet.UsedRange.Columns.Count
strText = Cells(intRow, intCol).Text
strText = WorksheetFunction.Substitute(strText, "ö", "")
Select Case intCol
Case 1: strTmp = strTmp & strText & String(2 - Len(strText), " ")
Case 2: strTmp = strTmp & strText & String(5 - Len(strText), " ")
Case 3: strTmp = strTmp & strText & String(3 - Len(strText), " ")
Case 4: strTmp = strTmp & strText & String(1 - Len(strText), " ")
Case 5: strTmp = strTmp & strText & String(10 - Len(strText), " ")
Case 6: strTmp = strTmp & strText & String(4 - Len(strText), " ")
Case 7: strTmp = strTmp & strText & String(17 - Len(strText), " ")
Case 8: strTmp = strTmp & strText & String(5 - Len(strText), " ")
Case 9: strTmp = strTmp & strText & String(8 - Len(strText), " ")
Case 10: strTmp = strTmp & strText & String(4 - Len(strText), " ")
Case 11: strTmp = strTmp & strText & String(6 - Len(strText), " ")
Case 12: strTmp = strTmp & strText & String(12 - Len(strText), " ")
Case 13: strTmp = strTmp & strText & String(12 - Len(strText), " ")
Case 14: strTmp = strTmp & strText & String(39 - Len(strText), " ")
End Select
Next intCol
Print #1, strTmp
strTmp = ""
Next intRow
Close
End Sub
Bei dem Fett markierten komme ich nicht weiter, ich schaffe es nicht variabel zwischen Spalte 2 und egal zu gestalten.
Vielen Dank, wenn ihr es mal anschaut!