Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Script .getvalue() Not Working With Cells With a Formula In It

I have this google script for google sheets that moves rows of data from "Sheet1" to "Sheet2" when column 15 says "tracking", and it works perfectly fine when I type in "tracking" but I would like that column to be an IF equation something like IF(G:G="tracking not available at this time","","tracking"). But the code does not seem to recognize the formula change from "" to "tracking". Do I need to change the getvalue()? Or is there a different workaround to this issue? I've used =query(importrange) withing the spreadsheet to copy over data with a trigger word, but I really want this to be more of an archive system and add a row to the bottom of "Sheet2" whenever row15 on "sheet1"Thanks! Here is the code:

function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();

if(s.getName() == "Sheet1" && r.getColumn() == 14 && r.getValue() == "tracking") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Sheet2");
if(targetSheet.getLastRow() == targetSheet.getMaxRows()) {

  targetSheet.insertRowsAfter(targetSheet.getLastRow(), 20);
}
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
} 
like image 773
Ricky Adams Avatar asked Nov 14 '18 16:11

Ricky Adams


People also ask

How to load a variable in Google Apps Script using getvalues?

If you load a variable in Google Apps script using getValues, the variable will be an array that can load multiple values from the sheet. function myFunction () { var sheet = SpreadsheetApp.getActiveSheet (); var data = sheet.getDataRange ().getValues (); The data variable is a multi-dimensional array that holds all of the data from the sheet.

How to create and test a Google Script?

This is where you can create and test your Google Script. To give it a shot, try creating a Google Sheets script function that will read data from one cell, perform a calculation on it, and output the data amount to another cell. The function to get data from a cell is the getRange () and getValue () functions.

How do I get a value from a cell in Excel?

The function to get data from a cell is the getRange () and getValue () functions. You can identify the cell by row and column. So if you have a value in row 2 and column 1 (the A column), the first part of your script will look like this: This stores the value from that cell in the data variable.

How to get data from one cell to another in Google Sheets?

To give it a shot, try creating a Google Sheets script function that will read data from one cell, perform a calculation on it, and output the data amount to another cell. The function to get data from a cell is the getRange () and getValue () functions. You can identify the cell by row and column.


1 Answers

I had an issue with this recently I spent about 3 hours debugging something yesterday and this was the culprit.

try using r.getDisplayValue() instead of r.getValue

I am still new to this myself, and feel free to correct me if I am wrong, because if there is a different reason I would really love to know!!! It seems that if a value in a cell is not typed in but placed there through a formula such as =query() or a similar method, I don't think it actually sees that there is a value in the cell. (I got null values or the formula itself) If you use getDisplayValue, it "should" get the value that you actually see in the cell.

like image 175
SRW Avatar answered Nov 15 '22 09:11

SRW