0

I have recorded a macro that adds formula onto the end of a cell

function addpricemultiplier() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('H5:1000').activate();
  spreadsheet.getCurrentCell().setFormula('=0.3*GOOGLEFINANCE("CURRENCY:USDAUD")');
  spreadsheet.getRange('H5:1000').activate();
};

The problems I have are that it will only change if the value is =0.3, I am unsure how to change it so that it will add the formula on no matter what, and of less importance I have made the macro from H5 onto 1000, I am unsure if there is a way to make it just go on as long as the sheet is there instead of pre determining where it will go to.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Jesse
  • 1
  • Welcome to [Stack Overflow](https://stackoverflow.com/tour). It is unclear why you would want to use a macro since that looks doable with a plain vanilla spreadsheet formula. You should probably have a dedicated cell for fetching the exchange rate, and refer to that cell instead of repeating the fetch on every row. Consider sharing a publicly editable [sample spreadsheet](https://webapps.stackexchange.com/a/138383/269219) with _realistic-looking_ data, and showing your _manually entered_ desired results there. – doubleunary Jul 17 '22 at 08:11
  • Your question can be greatly improved if you add a table to the question. [Tables](https://webapps.stackexchange.com/a/161855/) are a better alternative than spreadsheets to show your data structure. If you share spreadsheets, make sure to also add images of your sheet to avoid closure of your question, as questions here must be [self](https://meta.stackoverflow.com/a/260455/) [contained](https://meta.stackexchange.com/a/149892). [Your email address can also be accessed by the public](https://meta.stackoverflow.com/questions/394304/), when you share Google files. – TheMaster Jul 17 '22 at 09:50
  • Like @doubleunary, why would you want duplicates of the same formula in column H? If you had many GOOGLEFINANCE formulas you will notice a significant delay in performance as it queries its database for each formula. – TheWizEd Jul 17 '22 at 13:18

0 Answers0