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



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















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);











share|improve this question






















  • That is a bit of a condundrum with Google Sheets. getValue() only gets the value in the cell and it knows that formulas are not the value. Likewise getFormulas() gets the formulas as a string but if the cell contains only a value the string is blank. Now the condundrum is you can not overlay the value array with the formula array and use setValues(). You almost need to go through the formula array and put the formula if it exists in that cell as a string in the value array and then use setValues().

    – TheWizEd
    Nov 14 '18 at 17:20











  • @TheWizEd yeah that's exactly what I was running into. Thanks for the response.

    – Ricky Adams
    Nov 14 '18 at 17:30











  • Possible duplicate of e.range.getA1Notation() unable to track changes caused by formula update

    – TheMaster
    Nov 14 '18 at 18:48











  • @ThWizEd That's not what op is asking.

    – TheMaster
    Nov 14 '18 at 18:49

















-1















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);











share|improve this question






















  • That is a bit of a condundrum with Google Sheets. getValue() only gets the value in the cell and it knows that formulas are not the value. Likewise getFormulas() gets the formulas as a string but if the cell contains only a value the string is blank. Now the condundrum is you can not overlay the value array with the formula array and use setValues(). You almost need to go through the formula array and put the formula if it exists in that cell as a string in the value array and then use setValues().

    – TheWizEd
    Nov 14 '18 at 17:20











  • @TheWizEd yeah that's exactly what I was running into. Thanks for the response.

    – Ricky Adams
    Nov 14 '18 at 17:30











  • Possible duplicate of e.range.getA1Notation() unable to track changes caused by formula update

    – TheMaster
    Nov 14 '18 at 18:48











  • @ThWizEd That's not what op is asking.

    – TheMaster
    Nov 14 '18 at 18:49













-1












-1








-1








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);











share|improve this question














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);








if-statement google-apps-script google-sheets getvalue






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 16:41









Ricky AdamsRicky Adams

556




556












  • That is a bit of a condundrum with Google Sheets. getValue() only gets the value in the cell and it knows that formulas are not the value. Likewise getFormulas() gets the formulas as a string but if the cell contains only a value the string is blank. Now the condundrum is you can not overlay the value array with the formula array and use setValues(). You almost need to go through the formula array and put the formula if it exists in that cell as a string in the value array and then use setValues().

    – TheWizEd
    Nov 14 '18 at 17:20











  • @TheWizEd yeah that's exactly what I was running into. Thanks for the response.

    – Ricky Adams
    Nov 14 '18 at 17:30











  • Possible duplicate of e.range.getA1Notation() unable to track changes caused by formula update

    – TheMaster
    Nov 14 '18 at 18:48











  • @ThWizEd That's not what op is asking.

    – TheMaster
    Nov 14 '18 at 18:49

















  • That is a bit of a condundrum with Google Sheets. getValue() only gets the value in the cell and it knows that formulas are not the value. Likewise getFormulas() gets the formulas as a string but if the cell contains only a value the string is blank. Now the condundrum is you can not overlay the value array with the formula array and use setValues(). You almost need to go through the formula array and put the formula if it exists in that cell as a string in the value array and then use setValues().

    – TheWizEd
    Nov 14 '18 at 17:20











  • @TheWizEd yeah that's exactly what I was running into. Thanks for the response.

    – Ricky Adams
    Nov 14 '18 at 17:30











  • Possible duplicate of e.range.getA1Notation() unable to track changes caused by formula update

    – TheMaster
    Nov 14 '18 at 18:48











  • @ThWizEd That's not what op is asking.

    – TheMaster
    Nov 14 '18 at 18:49
















That is a bit of a condundrum with Google Sheets. getValue() only gets the value in the cell and it knows that formulas are not the value. Likewise getFormulas() gets the formulas as a string but if the cell contains only a value the string is blank. Now the condundrum is you can not overlay the value array with the formula array and use setValues(). You almost need to go through the formula array and put the formula if it exists in that cell as a string in the value array and then use setValues().

– TheWizEd
Nov 14 '18 at 17:20





That is a bit of a condundrum with Google Sheets. getValue() only gets the value in the cell and it knows that formulas are not the value. Likewise getFormulas() gets the formulas as a string but if the cell contains only a value the string is blank. Now the condundrum is you can not overlay the value array with the formula array and use setValues(). You almost need to go through the formula array and put the formula if it exists in that cell as a string in the value array and then use setValues().

– TheWizEd
Nov 14 '18 at 17:20













@TheWizEd yeah that's exactly what I was running into. Thanks for the response.

– Ricky Adams
Nov 14 '18 at 17:30





@TheWizEd yeah that's exactly what I was running into. Thanks for the response.

– Ricky Adams
Nov 14 '18 at 17:30













Possible duplicate of e.range.getA1Notation() unable to track changes caused by formula update

– TheMaster
Nov 14 '18 at 18:48





Possible duplicate of e.range.getA1Notation() unable to track changes caused by formula update

– TheMaster
Nov 14 '18 at 18:48













@ThWizEd That's not what op is asking.

– TheMaster
Nov 14 '18 at 18:49





@ThWizEd That's not what op is asking.

– TheMaster
Nov 14 '18 at 18:49












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer























  • thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

    – Ricky Adams
    Nov 16 '18 at 16:45











  • Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

    – SRW
    Nov 16 '18 at 18:08











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304976%2fgoogle-script-getvalue-not-working-with-cells-with-a-formula-in-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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.






share|improve this answer























  • thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

    – Ricky Adams
    Nov 16 '18 at 16:45











  • Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

    – SRW
    Nov 16 '18 at 18:08















0














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.






share|improve this answer























  • thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

    – Ricky Adams
    Nov 16 '18 at 16:45











  • Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

    – SRW
    Nov 16 '18 at 18:08













0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 15:08









SRWSRW

13




13












  • thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

    – Ricky Adams
    Nov 16 '18 at 16:45











  • Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

    – SRW
    Nov 16 '18 at 18:08

















  • thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

    – Ricky Adams
    Nov 16 '18 at 16:45











  • Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

    – SRW
    Nov 16 '18 at 18:08
















thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

– Ricky Adams
Nov 16 '18 at 16:45





thanks for the feedback! I tried playing around with the getDisplayValue(), but that didn't seem to work. It still doesn't register it to copy it over to the

– Ricky Adams
Nov 16 '18 at 16:45













Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

– SRW
Nov 16 '18 at 18:08





Something else you could try. An extra space in the cell whether it is at the start or at the end can also cause trouble when reading the value.

– SRW
Nov 16 '18 at 18:08



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304976%2fgoogle-script-getvalue-not-working-with-cells-with-a-formula-in-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo