Advertisement
Lodscripts

20190609 Lock Output cell LODSCRIPT

Jun 9th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://stackoverflow.com/questions/56323053/how-to-lock-the-result-of-the-output-cell-once-it-meets-a-criteria-from-subseq
  2.  
  3. //https://docs.google.com/spreadsheets/d/1UjjMnLmNbEDUfXjeCIOgBZwYqTeXdm_t_4N45OL0k6I/edit#gid=0
  4.  
  5. //https://youtu.be/DEI7RGRotcs
  6.  
  7. /**
  8. * Locks the Status of a cell according to criteria and Colors and bolds the specific words of status
  9. *
  10. * @param arg3:  Colors "VALID" Status to orange, "PENDING" Status to green, and "APPROVED" to purple
  11. *
  12. * @customfunction
  13. */
  14.  
  15.  
  16. function LOCKVALUECOLORBOLDWORDS(arg3) {
  17.  
  18.       var app = SpreadsheetApp;
  19.       var activeSheet = app.getActiveSpreadsheet().getActiveSheet();
  20.  
  21.       //(read left to right) get the value from range A1:A1, from active sheet, and assign it the variable "fixedvalueCell"
  22.       var fixedvalueCell = activeSheet.getRange(1, 1).getValue();
  23.  
  24.       //(read left to right) get the value from range B1:B1, from active sheet, and assign it the variable "changingvalueCell"
  25.       var changingvalueCell = activeSheet.getRange(1, 2).getValue();
  26.  
  27.       //(read left to right) get the value from range C1:C1, from active sheet, and assign it the variable "approveCell"
  28.       var approveCell = activeSheet.getRange(1, 3).getValue();
  29.  
  30.       //(read left to right) get the value from range D1:D1, from active sheet, and assign it the variable "statusCell"
  31.       var statusCell = activeSheet.getRange(1, 4).getValue();
  32.  
  33.  
  34.  
  35.  
  36.       //[1.] if the value of approveCell is not-blank, then set/print "APPROVED" into D1, and color it to purple, and bold it.
  37.       if
  38.         (approveCell !== "") {
  39.         activeSheet.getRange(1, 4).setValue("APPROVED").setFontColor("#7F00FF").setFontWeight("bold");
  40.       }
  41.  
  42.  
  43.       //[2.] if the value of changingvalueCell is smaller or equal to the value of fixedvalueCell, then set/print "PENDING" into D1, and color it to green, and bold it.
  44.         else if
  45.         (changingvalueCell <= fixedvalueCell) {
  46.         activeSheet.getRange(1, 4).setValue("PENDING").setFontColor("#7FFF00").setFontWeight("bold");
  47.       }
  48.  
  49.  
  50.       //[3.] if the value of statusCell is "PENDING", then set/print "PENDING" into D1, and color it to green, and bold it.
  51.         else if
  52.         (statusCell == "PENDING") {
  53.         activeSheet.getRange(1, 4).setValue("PENDING").setFontColor("#7FFF00").setFontWeight("bold");
  54.       }
  55.  
  56.  
  57.       //[4.] if all [1.] and [2.] and [3.] IF statements are FALSE (for everything else), then set/print "VALID" into D1, and color it to orange, and bold it.
  58.         else {
  59.         activeSheet.getRange(1, 4).setValue("VALID").setFontColor("#FF6600").setFontWeight("bold");
  60.       }
  61.  
  62.  
  63.       var result = arg3;
  64.  
  65.       return result;
  66.  
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement