mit dem aufgeführten Code soll die nächste leere Zeile gefunden werden, beginnend ab Zeile 5, die Zeile 4 (dient als Vorlage; Zeile 3 und 4 sind versteckt)) soll dort hin kopiert werden, nur Formate und Formeln sollen beibehalten werden, die aktive Zelle soll in der neu eingefügten Zeile Spalte A sein.
Klappt auch so weit, nur dass die Kopiermarkierung immer in Zeile 4 hängen bleibt
(gestrichelte Umrandung)und die neue Zeile ist komplett markiert und nicht Zelle A.
Wo liegt mein Fehler?
Danke im voraus
Mike
Sub insert_row()
Dim lastrow As Long
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox "Lastrow is " & lastrow
Application.EnableEvents = False
Application.ScreenUpdating = False
If lastrow > 4 Then
ActiveSheet.Cells(4, 1).EntireRow.Hidden = False
ActiveSheet.Cells(4, 1).EntireRow.Select
ActiveSheet.Cells(4, 1).EntireRow.Hidden = True
With Selection
.EntireRow.Copy
.Offset(lastrow - 3).EntireRow.PasteSpecial Paste:=xlPasteFormulas
.Offset(lastrow - 3).EntireRow.PasteSpecial Paste:=xlPasteFormats
.Offset(lastrow - 3).EntireRow.PasteSpecial Paste:=xlPasteValidation
.Offset(lastrow - 3).EntireRow.Hidden = False
End With
ActiveSheet.Cells(lastrow + 1, 1).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents
ActiveSheet.Cells(ActiveCell.Row, "A").Select
End If
End Sub