Public Sub Insert_New_Row()
Dim filteredRange As Range
Dim r1 As Range, r2 As Range
Dim areaNum As Long
With ActiveSheet
If .FilterMode Then
'Sheet is filtered
'Set range of active cell
Set r1 = ActiveCell
'Determine filtered area number of active cell
Set filteredRange = .UsedRange.SpecialCells(xlCellTypeVisible)
For areaNum = 1 To filteredRange.Areas.Count
If Not Application.Intersect(r1, filteredRange.Areas(areaNum)) Is Nothing Then
Exit For
End If
Next
'Determine range of row below active cell. This is either the row below in the same area, or the first row in the next area, or the row below the last area
'Assume it's the row below in same area
Set r2 = Application.Intersect(r1.Offset(1), filteredRange.Areas(areaNum))
If r2 Is Nothing Then
'Not in same area
If areaNum < filteredRange.Areas.Count Then
'First row in next area
Set r2 = filteredRange.Areas(areaNum + 1)(1)
Else
'Row below last area
Set r2 = filteredRange.Areas(areaNum).Rows(filteredRange.Areas(areaNum).Rows.Count + 1)
End If
End If
Else
'Sheet isn't filtered
Set r1 = ActiveCell
Set r2 = ActiveCell.Offset(1)
End If
End With
'Copy row r1 and insert at r2
r1.EntireRow.Select
Selection.Copy
r2.EntireRow.Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub