Hi there, it's been a while without posting or helping. I have tried may ways to solve this but it defeated me.
I am working with loans, and I'm trying to program a routine that adds every installment a client owes, so I can know the total amount owed, depending on how many unpaid installments she has.
Let say for a client I have every installment in column A (rows 1 to 5), and in column B, I want to add them all. The output should be
Cell B1: "sum(A1:A5)"
Cell B2: "sum(A2:A5)"
Cell B3: "sum(A3:A5)"... and so forth
Since I have many loans, I need a dinamic routine to that sums every installment, where amount of installments vary from client to client.
My proposal is (adding from the last installment to the first one):
months = 4 'an example For j = 0 To months - 1 initial_row = ActiveCell.Row 'because I run this several times. In this example I am in row 18 ActiveCell.FormulaR1C1 = "=SUM(AJ" & initial_row & ":AJ" & initial_row + j & ")" 'I expect to have SUM(AJ18:AJ18), SUM(AJ17:AJ18), SUM(AJ16:AJ18)... ActiveCell.Offset(-1, 0).Select Next
For some reason this is not working, and what I see in Excel after running it is: SUM('AJ18':'AJ18'), which doesn't work.
Could anyone tell me what may be wrong in this code. If you have an alterative solution, it is more than welcome