Google Script

26 views
Skip to first unread message

Richard Benedict Yap

unread,
Sep 21, 2021, 1:21:33 AM9/21/21
to Google Apps Script Community
Good day! 

I want to get the values of "config!a2:a" & "config!b2:b"

it works when "config!a2" & "config!b2" is only the range I set but is it possible to get the values of "config!a2:a" & "config!b2:b" 

===============================================

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "raw" ) {
    var r = s.getActiveCell();
  
    var watchColumn = s.getRange('config!A2').getValues();
    var dateColumn = s.getRange('config!B2').getValues();

    var watchColumn1 = s.getRange('config!A3').getValues();
    var dateColumn1 = s.getRange('config!B3').getValues();
    
    if( r.getColumn() == watchColumn ) { //checks the column
      var nextCell = r.offset(0, (dateColumn)-watchColumn);
      if( nextCell.getValue() === '' || nextCell.getValue() != '') 
        nextCell.setValue(new Date());
    }

    if( r.getColumn() == watchColumn1 ) { //checks the column
      var nextCell = r.offset(0, (dateColumn1)-watchColumn1);
      if( nextCell.getValue() === '' || nextCell.getValue() != '') 
        nextCell.setValue(new Date());
    }
  }
}

Clark Lind

unread,
Sep 21, 2021, 9:00:09 AM9/21/21
to Google Apps Script Community
Yes, it is possible to get the whole column range. But explain what you are trying to do. Are you simply trying to check if the active (edited) cell is in ColA, and then append a date in ColC? Then if ColC already has a date (last edited), append a new date in ColD, etc? Basically adding a new date and keep a history of dates the cell was edited? Your logic is sound, but there are easier ways to achieve your goal, if my assumption is correct.

Richard Benedict Yap

unread,
Sep 21, 2021, 7:51:02 PM9/21/21
to google-apps-sc...@googlegroups.com
Good day!

When a user changes the value of any cell in a "Watch column", it will apply date on "Date Column".
Basically, I will define all the columns in the "Watch Column"  and it will apply date modified in the "Date Column".

Any cells in ColA are changes, it will trigger date modified in ColJ.
.
.
.
Any cells in ColE are changes, it will trigger date modified in ColN.


image.png

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/09oazBD2_us/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/819f728e-ef47-40a9-bb19-90ecda3d5f63n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages