I use this macro to insert rows into a ledger and it was working correctly, but for some reason, the formula on the last column is not copying down correctly when I run the macro. Here is the macro:
Sub Insert_Rows()
If Selection.Rows.Count <> 1 Then Exit Sub
If Selection.Areas.Count <> 1 Then Exit Sub
With Selection.EntireRow
Selection.Locked = False
.Offset(-1).Copy
.Insert
On Error Resume Next
.Offset(-1).SpecialCells(xlCellTypeConstants, 23).ClearContents
On Error GoTo 0
End With
End Sub
Here is the formula:
=IF(AND(ISBLANK(H83),ISBLANK(I83)),"",SUM(K82-H83+I83))
When I select a cell in row 83 and run the macro, the formula in the newly inserted row should be this:
=IF(AND(ISBLANK(H83),ISBLANK(I83)),"",SUM(K82-H83+I83))
----Which it is. The code inserts a blank row in the row that is selected. However, the formula in the new row 84 should be this:
=IF(AND(ISBLANK(H84),ISBLANK(I84)),"",SUM(K83-H84+I84)); instead it is:
=IF(AND(ISBLANK(H84),ISBLANK(I84)),"",SUM(K82-H84+I84))
This code used to work, but for some reason today it is not. Any thoughts on what is happening? Locking or unlocking the cells that contain the formula has no effect.
Bookmarks