Copy the formula from a cell

320 views
Skip to first unread message

Maxime Gony

unread,
May 31, 2022, 3:27:04 AM5/31/22
to Google Apps Script Community
Hi Everyone,

I'm looking for a way to "import" the formula from a cell to another cell (and have it executed of course).

I want the formula I'm aiming for to be executed in the new cell.

How should I proceed ?

I've been looking/messing around and it doesn't sound like something there is a public solution to.

Regards,

Maxime

Clark Lind

unread,
May 31, 2022, 12:17:39 PM5/31/22
to Google Apps Script Community
You can do this fairly easily with Apps script or a macro. If you know the starting cell (that contains the formula) and destination cell (where you want the formula pasted) will always be the same,
The script is very easy. For example, if copying the formula from cell C2 to cell D3, see below. Once pasted, the formula will (should) update itself.

function pasteFormula() {
  var spreadsheet = SpreadsheetApp.getActive(); //gets the current 'active' sheet (wherever the mouse is)
   spreadsheet.getRange('C2').copyTo(spreadsheet.getRange('D3'), SpreadsheetApp.CopyPasteType.PASTE_FORMULA, false); //pretty self-explanatory. The 'false' on the end is an indicator regarding transpose (change rows to cols, or cols to rows)
};

Reply all
Reply to author
Forward
0 new messages