Google sheets macro won't set number format

Viewed 108

I am creating a macro to edit a CSV I regularly download from Square. It kept breaking and I figured out it isn't formatting columns as currency. None of the solutions I found worked, so I've saved the rest of the macro on a note and am simply trying to format 2 columns.
This is the macro created when I record manually setting the columns.

  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('J:K').activate();
  spreadsheet.getActiveRangeList().setNumberFormat('"$"#,##0.00');
};

When I run it actually removes all formatting (when I check a cell for formatting none of the formats are selected. When I manually formatting the columns works as intended.

2 Answers

Try

function myFunction() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('J:K').setNumberFormat('"$"#,##0.00');
}

enter image description here

The solution offered didn't work. What did work was unchecking the convert text to numbers, dates, and formulas box on import. After that both my original macro and the new version offered worked as expected.

enter image description here

Related