Ok this code works.
If the next row is hidden it messes up, I suppose this depends on your point of view.
So if you select Row 5 and Row 6 is hidden
Then a new row 6 is created. The new row 6 is hidden,
the original row 6 becomes row 7 and is not hidden.
Sub CopyAndInsertRow()
ActiveSheet.Unprotect
R = ActiveCell.Row
LC = Selection.SpecialCells(xlCellTypeLastCell).Column
With Range(Cells(R, 1), Cells(R, LC))
.Copy
.Insert Shift:=xlDown
End With
On Error Resume Next
With Range(Cells(R + 1, 1), Cells(R + 1, LC))
.SpecialCells(xlCellTypeConstants).Clear
End With
On Error GoTo 0
Application.CutCopyMode = False
ActiveSheet.Protect , AllowFiltering:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
End Sub
This Version inserts the copied row at row 7, below the hidden row.
Sub CopyAndInsertRow()
ActiveSheet.Unprotect
R = ActiveCell.Row
LC = Selection.SpecialCells(xlCellTypeLastCell).Column
O = 1
With Range(Cells(R, 1), Cells(R, LC))
10 If Rows(R + O).RowHeight = 0 Then O = O + 1: GoTo 10
.Copy
Range(Cells(R + O, 1), Cells(R + O, LC)).Insert Shift:=xlDown
End With
On Error Resume Next
With Range(Cells(R + O, 1), Cells(R + O, LC))
.SpecialCells(xlCellTypeConstants).Clear
End With
On Error GoTo 0
Application.CutCopyMode = False
ActiveSheet.Protect , AllowFiltering:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
End Sub
Bookmarks