Hi,
I am making a Macro which will have different last rows every time I will be using it.
I have been able to write the macro so that column D and E sum in the last row +1. Now I need to write a simple formula in column F (LastRow+1), using the values in the last rows of column D and E.
If the formula was hard printed it would be =E21/D21 (where row 21 contains the last value in the spreadsheet). I do however need the formula to be dynamic and use the last values in column E and D. Any suggestions?
Range("d1").Select
Selection.EntireColumn.Insert
Range("d3").Value = "Forvaltningshonorar i kr"
LastRow = Range("a4").End(xlDown).Row
Range("d4").Select
ActiveCell.Formula = "=e4/f4"
Range("d4").Select
Range(Selection, Selection.Offset(LastRow - Range("a4").Row, 0)).Select
Selection.FillDown
Range("d4").End(xlDown).Select
LastRow = ActiveCell.Row
Cells(LastRow + 1, "d").Formula = "=SUM(d4:d" & LastRow & ")"
Range("e4").End(xlDown).Select
LastRow = ActiveCell.Row
Cells(LastRow + 1, "e").Formula = "=SUM(e4:e" & LastRow & ")"
Range("f4").End(xlDown).Select
LastRow = ActiveCell.Row
Help is highly appreciated!
I am making a Macro which will have different last rows every time I will be using it.
I have been able to write the macro so that column D and E sum in the last row +1. Now I need to write a simple formula in column F (LastRow+1), using the values in the last rows of column D and E.
If the formula was hard printed it would be =E21/D21 (where row 21 contains the last value in the spreadsheet). I do however need the formula to be dynamic and use the last values in column E and D. Any suggestions?
Range("d1").Select
Selection.EntireColumn.Insert
Range("d3").Value = "Forvaltningshonorar i kr"
LastRow = Range("a4").End(xlDown).Row
Range("d4").Select
ActiveCell.Formula = "=e4/f4"
Range("d4").Select
Range(Selection, Selection.Offset(LastRow - Range("a4").Row, 0)).Select
Selection.FillDown
Range("d4").End(xlDown).Select
LastRow = ActiveCell.Row
Cells(LastRow + 1, "d").Formula = "=SUM(d4:d" & LastRow & ")"
Range("e4").End(xlDown).Select
LastRow = ActiveCell.Row
Cells(LastRow + 1, "e").Formula = "=SUM(e4:e" & LastRow & ")"
Range("f4").End(xlDown).Select
LastRow = ActiveCell.Row
Help is highly appreciated!