467,910 Members | 1,573 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,910 developers. It's quick & easy.

How do you set Accounting format in Google Script App?

Brilstern
100+
In the function below, I am using column H to adjust the format of column F. I would like to adjust this format to an accounting format, but I am struggling to do so. Does anyone know how to convert this string, "USD":"[Red][$$]#,##0.00", to an accounting format in the Google Script App?

Expand|Select|Wrap|Line Numbers
  1. function onEdit(e){
  2.  
  3.     var sheetName = "Debt"; //name of sheet to adjust formatting on
  4.     var currencyCol = 8; //column H
  5.     var amountCol = 6; //column F
  6.     var defaultFormat = "[$]#,##0.00";
  7.     var currencyFormat = {"USD":"[Red][$$]#,##0.00",
  8.                           "GBP":"[Red][$]#,##0.00",
  9.                           "EUR":"[Red][$]#,##0.00"};
  10.  
  11.     var r = e.range;
  12.     if(e.source.getSheetName()==sheetName && r.getColumn() == currencyCol){ //edits one cell at a time
  13.       var uf = currencyFormat[r.getValue()];
  14.       uf = uf?uf:defaultFormat;
  15.       r.offset(0,amountCol-currencyCol).setNumberFormat(uf);
  16.     }
  17. }
Feb 2 '20 #1
  • viewed: 1642
Share:

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by tim | last post: by
6 posts views Thread by shapper | last post: by
10 posts views Thread by Steve | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.