I have gotten so much excellent help from this site. This is my first question. I have googled all the wordings I can think of and looked at all possible related threads on this site and others, and cannot find an explanation.
I am trying to automate a sheet into which a data table of variable size will be pasted.
Here is the formula I am trying to replicate:
=(C26-B26)/B26
(percent variation to previous month)
Edited to respond to a comment: This formula is in cell C28 in the sheet I am being asked to automate. So it is referring to cells two rows above and 1 column to the left of the cell where the formula is located.
Here is my code which the editor accepts:
ActiveCell.Formula = "=(" & (Cells(Index(Row() - 2), Index(Col())).Address(False, False)) & "-" & Cells(Index(Row() - 2), Index(Col() - 1)).Address(False, False) & "/" & Cells(Index(Row() - 2), Index(Col() - 1)).Address(False, False) & ")"
When I run this, I get a compile error: Sub or Function not defined
and the first instance of row
is highlighted.
It seems to me I read somewhere that one cannot calculate with Row()
and Column()
but I have not been able to find that again. I have found many examples online of people using Row()
and Column()
in this way to find cells adjacent to the active cell.
I appreciate any help and suggestions.
Thank you in advance.