Google Sheets: Formula MID doesnt work on macro?

89 Views Asked by At

I run this macro into my Sheets but for some reason the formula MID is returning #NAME? but if I erase one word and write down again it returns the right number. I erased the beginning to fit in here :)

function iOS() {
  var spreadsheet = SpreadsheetApp.getActive();
[...]
  spreadsheet.getRange('K2').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Página19'), true);
  spreadsheet.getCurrentCell().setFormula('=MID(F2;(SEARCH(":";F2;(SEARCH("af_revenue";F2))))+1;LEN(G2))');
  spreadsheet.getRange('K2').activate();
  spreadsheet.getActiveRange().autoFill(spreadsheet.getRange('K2:L2'), SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
  spreadsheet.getActiveRange().autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
  spreadsheet.getRange('K6').activate();
  spreadsheet.getRange('F:K').activate();
  spreadsheet.getRange('F:K').createFilter();
  spreadsheet.getRange('H1').activate();
  var criteria = SpreadsheetApp.newFilterCriteria()
  .setHiddenValues(['', 'None'])
  .build();
  spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(8, criteria);
  spreadsheet.getRange('K32').activate();
  var currentCell = spreadsheet.getCurrentCell();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Valores'), true);
  spreadsheet.getRange('\'Página19\'!K32:K288').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.getRange('E16').activate();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
  currentCell.activateAsCurrentCell();
  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
  spreadsheet.getRange('G2').activate();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getRange('G2:G3247').activate();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.UP).activate();
  currentCell.activateAsCurrentCell();
  spreadsheet.getRange('F2:F3').activate();
  currentCell.activateAsCurrentCell();
  spreadsheet.getRange('H2').activate();
  spreadsheet.getRange('G2:G3248').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.getRange('H2').activate();
  currentCell = spreadsheet.getCurrentCell();
  spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
  currentCell.activateAsCurrentCell();
  spreadsheet.getRange('H1').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};

I think the macro isnt runnning the function as it should be but I dont know why. So the rest of cells that I should work with the numbers from the formula are all empty at the end. I need this formula 'cause the report I downloaded everyday bring me the numbers like this: "189.097.092.504.234.532..." and I need them like this : "189,097092505234532..." If there is another formula that do this same thing and works on macro it would help me a lot :)

1

There are 1 best solutions below

0
Wicket On

In your formula use comma instead of semi-colon as function parameters separator

The above because the default separators in Google Sheets (used in the "background" ) are

  • decimal : dot (full stop)
  • formula parameters: comma

The use of semi-colon separator and the corresponding conversion to what the "formula engine" can understand is done by the web browser.