Hallo!
Ich verwende ein Excel-Makro zum Exportieren gewisser Spalten nach csv.
Bei diesem würde ich nun gerne jene Zeilen überspringen, die in der Spalte 34 den Wert 0 haben.
Kann mir hier jemand weiterhelfen?
So sieht mein bisheriges Makro aus:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wert As String
Dim pfad As String
Dim txtfile As String
pfad = „…“
txtfile = pfad & „output.csv“
Open txtfile For Output As #1
i = 2
Do While Cells(i, 2).Value „“
Print #1, Cells(i, 1) & „;“ & Cells(i, 2) & „;“ & Cells(i, 3) & „;“ & Cells(i, 4) & „;“ & Cells(i, 5) & „;“ & Cells(i, 6) & „;“ & Cells(i, 34) & „;“ & Cells(i, 35) & „;“ & Cells(i, 36)
i = i + 1
Loop
Close
End Sub
Besten Dank!
Becka
Hallo Becka
Du musst die Spalte 34 im Loop testen und falls der Wert 0 ist den print auslassen
i = 2
Do While Cells(i, 2).Value „“
if cells(i,34)=0 then goto 100
Print #1, Cells(i, 1) & „;“ & Cells(i, 2) & „;“ & Cells(i, 3) & „;“ & Cells(i, 4) & „;“ & Cells(i, 5) & „;“ & Cells(i, 6) & „;“ & Cells(i, 34) & „;“ & Cells(i, 35) & „;“ & Cells(i, 36)
i = i + 1
100
Loop
Gruss
pepo
Danke pepo2801 für deine rasche Rückmeldung!
Leider hängt sich jedoch beim Ausführen des Makros immer das Programm (also Excel) auf …
Leider hängt sich jedoch beim Ausführen des Makros immer das
Programm (also Excel) auf …
Hallo Becka,
Excel ist weg vom Bildschirm? Fehlermeldungen?
vielleicht fehlt da nur ein Doppelpunkt nach den zweiten 100, k.A.
Probier’s mal so:
Option Explicit
Private Sub Workbook\_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim FF As Long, Zei As Long, Spa As Long, Satz As String
FF = FreeFile
Const pfad As String = "...\"
Const txtfile As String = "output.csv"
With Worksheets("Tabelle1")
Open pfad & txtfile For Output As #FF
For Zei = 2 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(Zei, 34) "" Then
Satz = ""
For Spa = 1 To 36
If Spa = 7 Then Spa = 34
Satz = Satz & ";" & Cells(Zei, Spa)
Next Spa
Print #FF, Mid(Satz, 2)
End If
Next Zei
Close #FF
End With
End Sub
Gruß
Reinhard