1

I'm trying to insert a row at the bottom of the range, but nothing happens when I run the below code. If I remove the "1" in

Cells(nextRow, 1).EntireRow.Insert

It will insert a row at the top of the range.

Sub newRow()

Application.ScreenUpdating = False
 Sheet1.Activate

'goes to the row at the bottom of the range
nextRow = Cells(Rows.Count, 1).End(xlUp).row + 1

'inserts new row
Cells(nextRow, 1).EntireRow.Insert

Application.ScreenUpdating = True

End Sub
Vityata
  • 42,633
  • 8
  • 55
  • 100
pam_param
  • 162
  • 1
  • 13

1 Answers1

2

Inserting a row at the bottom of the range is not visible - and it is an empty row, which is not different than the unused empty rows. Anyway, inserting a row before the last one of the range is quite visible:

Sub NewRow()

    Dim nextRow As Long

    With Sheet1
        nextRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Cells(nextRow, 1).EntireRow.Insert
    End With

End Sub

enter image description here

Usin With Sheet1 and .Cells() instead of Select and Activate is a good practice -How to avoid using Select in Excel VBA

Vityata
  • 42,633
  • 8
  • 55
  • 100