I am new to VBA and am trying to write VBA code that could add a new row if the last row is empty. However, when I use this code what happens is that it adds rows in locations that don’t make sense. My last row is row 15. When I try to run the code for row 15 it adds a row after row 15 regardless whether it is empty or not, when I run the code for row 14 it adds a row after row 4 whether it is empty or not. When I run the code for row 13, it doesn’t do anything whether it is empty or not.
' ' Add_A_Row Macro ' Adding a row to a row that is not blank ' ' Keyboard Shortcut: Ctrl Shift A ' Dim sh As Worksheet Dim rw As Range Dim RowCount As Integer RowCount = 0 Set sh = ActiveSheet For Each rw In sh.Rows If sh.Cells(rw.Row, 15).Value <> "" Then rw.Insert Shift:=xlShiftDown, CopyOrigin:=xlInsertFormatOriginConstant Debug.Print ("Hit") Exit For End If Next rw End Sub