1
votes

I'm trying to do a few things with a piece of script but cannot get it all down. In row 2 of my sheet I have a series of consecutive dates based on the first of each month (British notation) e.g 01/08/2016, 01/09/2016, 01/10/2016. I then have a formula in rows 14 and 15 which I would like to be fixed (copy / paste value) when today's date matches that in row 2.

I feel that I need to run a few things -

  1. Schedule a script to run once per day to check if any value in row 2 is equal to today's date. If true then...
  2. Copy / paste values of the numbers in rows 14 and 15 and the column where the date matches.

Maybe an index/match is needed to verify part 1 but I'm really in the dark on how to do it.

Thanks for any assistance.

1
Hi Davey. What have you tried so far? Take a look at How to ask a good question. - Brady

1 Answers

0
votes

I think that I've now managed to crack it. In row 1 I have put in a helper formula which checks the date in row 2 against today's date and puts "TRUEMONTH" in the cell if it matches. My clunky code is then as follows (it still needs some tidying up for the sheet refs etc) -

function ColCheck() {
  var name = "TRUEMONTH";
  var name1 = "PASTE_ME_AS_VALUE";

   var range = SpreadsheetApp.getActiveSheet().getDataRange()
   var values = range.getValues();
   var range1 = SpreadsheetApp.getActiveSheet().getDataRange()
   var values1 = range1.getValues();

  for (var row in values) {
    for (var col in values[row]) {
      if (values[row][col] == name) {

   for (var row1 in values1) {
    for (var col1 in values1[row1]) {
      if (values1[row1][col1] == name1) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
        var row = parseInt(row1) + 1;
        var col = parseInt(col) + 1;
  var source = ss.getActiveSheet().getRange([row],[col]);

  source.copyTo(ss.getActiveSheet().getRange([row],[col]), {contentsOnly: true});   
      }
     }
    }      
   }
  }
 }
}