Excel Insert formula in column A & B for any row where column D is not null/blank
Posted on 2013-01-20
I have a formula in A2 and B2 and I am currently using the following to auto-fill the formula from A2 "=M2-7" into column A and "=L2" into column B of any row where column D is not blank/null. The problem is that it's not very consistent. sometimes it works and sometimes it doesn't.
Seems like it would be better to just write the formula into each cell where D is not blank/null?
This is how I am doing it now.
Sub Autofill ()
Dim lastrow As Long
lastrow = Worksheets("Engines").Cells(Rows.Count, "D").End(xlUp).Row
Selection.AutoFill Destination:=Range("A2:A" & lastrow)
Selection.AutoFill Destination:=Range("B2:B" & lastrow)