V
V
Vladimir D2019-08-03 21:48:39
Google Apps Script
Vladimir D, 2019-08-03 21:48:39

How to delete certain columns using a Google Spreadsheet script and replace values ​​in a column?

It is necessary to make a script in Google Spreadsheet so that when it is launched, certain columns (C, D, E) are deleted, and in column F in empty cells the word "no" is written, and in cells in which there is any numeric value greater than zero, the word "is" is written ".
Tell me who knows, or please give some leading information. What functions to use or where to read.
I'm trying to do it with macros. I run macros, delete columns, then do a range replacement using regular expressions.
.*\d (In stock)
^$ (Out of stock)
---
But when I run the macro, it only removes the columns and does nothing else.
And the piece of code itself is not complete

function myFunction() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('F:F').activate();
  spreadsheet.setCurrentCell(spreadsheet.getRange('F10'));
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-08-05
@JohnnyBravo7

certain columns (C,D,E) were deleted

If we are talking about clearing values, then .clear() will do.
If we are talking directly about deleting, then .deleteColumns(X, Y) will do. But keep in mind that the columns are shifted when deleted.
Grab all the column values ​​with .getValues() and loop through each value. In a loop, we form a new array depending on the values. And then paste it in .setValues()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question