Hallo fwerner,
ich gehe davon aus, dass in Zeile 1 die Überschrift steht, und das ab Zeile 2 kopiert werden soll. Sonst muss ggf. NA angepasst werden. Die folgende Routine überschreibt auf Blatt 2 alles. Wenn das nicht erwünscht ist, muss ggf. angepasst werden.
Zum Code Einfügen mit Alt + F11 in VBE wechseln. Ggf. neues Modul einfügen mit Einfügen // Modul. Dann diesen Code reinkopieren:
’ Variablen deklarieren
Dim BN1 As String, BN2 As String, AN As String, BS As String, D As String
Dim N1 As Single, N2 As Single, NA As Single, NE As Single
Dim M1 As Single, M2 As Single, M3 As Single
Sub Kopieren()
’ Blattnamen
With ActiveWorkbook
BN1 = .Sheets(1).Name
BN2 = .Sheets(2).Name
’ Letzte Zeile ermitteln, initialisieren
.Sheets(BN1).Activate
’ Application.ScreenUpdating = False
With ActiveWorkbook.ActiveSheet
NE = .UsedRange.SpecialCells(xlCellTypeLastCell).Row
MsgBox ("letzte Zeile " & NE)
NA = 2
N2 = NA
’ Kopieren
For N1 = NA To NE
AN = Cells(N1, 1).Value
BS = Cells(N1, 2).Value
D = Cells(N1, 8).Value
M1 = Cells(N1, 9).Value
M2 = Cells(N1, 10).Value
M3 = M1 + M2
If M3 > 0 Then
Einfuegen
End If
With ActiveWorkbook
Sheets(BN1).Activate
End With
Next
End With
’ Application.ScreenUpdating = False
.Sheets(BN2).Activate
End With
End Sub
Private Sub Einfuegen()
’ Einfuegen
With ActiveWorkbook
.Sheets(BN2).Activate
With ActiveWorkbook.ActiveSheet
Cells(N2, 1).Value = D
Cells(N2, 2).Value = AN
Cells(N2, 3).Value = BS
Cells(N2, 4).Value = M1
Cells(N2, 5).Value = M2
N2 = N2 + 1
End With
End With
End Sub
Mit Alt + F11 auf Excel-Umgebung zurück und Routine mit Alt + F8 starten. Bitte mit erst mit Kopie des Excelsheets testen.
MfG MwieMichel
