Hi,
I created a script to created three separate equations in columns, P, Q and R. I have it working up to autofilling down for P and Q, but am now getting a Run time 1004 error when it tries to auto fill down from R2 to wherever the bottom would be. Any suggestions would be helpful!
Sub CalculateMarginNrMPercent()
' Calculates Margin $, Net Realization and Margin %
Dim lastRow As Long
Range("P2").Select
ActiveCell.FormulaR1C1 = "=RC[-3]-(RC[-2]+RC[-1])"
lastRow = Range("O" & Rows.Count).End(xlUp).Row
Range("P2").AutoFill Destination:=Range("P2:P" & lastRow)
'Net Realization
Range("Q2").Select
ActiveCell.FormulaR1C1 = "=(RC[-5]+RC[-4])/RC[-7]"
lastRow = Range("P" & Rows.Count).End(xlUp).Row
Range("Q2").AutoFill Destination:=Range("Q2:Q" & lastRow)
'Margin %
Range("R2").Select
ActiveCell.FormulaR1C1 = "=RC[-5]-(RC[-4]+RC[-3])/RC[-5]"
lastRow = Range("R" & Rows.Count).End(xlUp).Row
Selection.AutoFill Destination:=Range("R2:R" & lastLiveRow), Type:=xlFillDefault
End Sub
I created a script to created three separate equations in columns, P, Q and R. I have it working up to autofilling down for P and Q, but am now getting a Run time 1004 error when it tries to auto fill down from R2 to wherever the bottom would be. Any suggestions would be helpful!
Sub CalculateMarginNrMPercent()
' Calculates Margin $, Net Realization and Margin %
Dim lastRow As Long
Range("P2").Select
ActiveCell.FormulaR1C1 = "=RC[-3]-(RC[-2]+RC[-1])"
lastRow = Range("O" & Rows.Count).End(xlUp).Row
Range("P2").AutoFill Destination:=Range("P2:P" & lastRow)
'Net Realization
Range("Q2").Select
ActiveCell.FormulaR1C1 = "=(RC[-5]+RC[-4])/RC[-7]"
lastRow = Range("P" & Rows.Count).End(xlUp).Row
Range("Q2").AutoFill Destination:=Range("Q2:Q" & lastRow)
'Margin %
Range("R2").Select
ActiveCell.FormulaR1C1 = "=RC[-5]-(RC[-4]+RC[-3])/RC[-5]"
lastRow = Range("R" & Rows.Count).End(xlUp).Row
Selection.AutoFill Destination:=Range("R2:R" & lastLiveRow), Type:=xlFillDefault
End Sub