4

This is a follow-up to Copying data to another sheet based on the month of a date, with a different requirement: instead of one-way data transfer (from Master sheet to others), two-directional transfer is needed.

Background

I have a sheet (Master) which has rows of data regarding different types of projects and deliverables.

One column in this sheet has a date value under column header "closingDate". The deliverable dates extend through the year. For example. we may create an entry today in the Master, for a project that is due to close in September of next year.

We need to be able to see what are the deliverables for a particular month. The years don't matter. All projects closing in Jan 2016, 2017, 2018, etc.

For reasons that I can not state we can't use filter or filter views in the Master Sheet.

An ideal solution for us would be to have sheets named Jan, Feb, March, April, etc.

Each time a record is added to the Master, depending upon the month of the closingDate a copy of the record is made in the sheet named after the month. Each time the record is edited in the master sheet the corresponding record is also updated.

New aspect

While the Filter works well, it has engineered another demand for me. Is it possible for creating the subset (filtered by Month) in a way that if we were to make changes in that subset view, those changes would cascade back to the Master. Would QUERY work? Or do I have to resort to a script. Or it is not possible.

  • 1
    You have to use a script – daniel Jan 26 '16 at 4:30
1

From the question

Is it possible for creating the subset (filtered by Month) in a way that if we were to make changes in that subset view, those changes would cascade back to the Master. Would QUERY work? Or do I have to resort to a script. Or it is not possible.

Short answer

Google Sheets doesn't have a built-in feature that syncs two spreadsheets so you have to use something that extends it.

Explanation

Built-in functions like QUERY are not able to make make changes to another range. They could only return a value or an array of values. The same apply to custom functions.

Below is included a very simple Google Apps Script code example that exports the value of an edited cell to a cell of another spreadsheet. That code could be added to two spreadsheets to export the edited cells values to each other in order to have a "two way sync" between those spreadsheets.

It's purpose is to show that it's possible to sync two spreadsheets by using Google Apps Script. In order to make it work to sync a master sheet with filtered sheet to logic to find which rows are the match in the other file should be added. Usually this is done using an unique ID.

Broad instructions

  1. Copy the code to script projects bounded to the each spreadsheet and update the targetID and targetSheetName variable definition code lines (lines 1 and 2).
  2. Add a On Edit installable triggers to each script project.

Code

var targetID = 'spreadsheet-id';
var targetSheetName = 'Sheet1';

function onEdit(e) {
  // Get the event object properties
  var range = e.range;
  var value = e.value;
  //Get the cell position 
  var row = range.getRowIndex();
  var column = range.getColumnIndex();
  exportValue(row,column,value)
}

function exportValue(row,column,value) {
  var ss = SpreadsheetApp.openById(targetID);
  var s = ss.getSheetByName(targetSheetName); 
  var target = s.getRange(row, column);
  target.setValue(value);
}

Limit the changes to be synced

In order to limit the changes to be synced add rules to the code. The JavaScript comparators ==, ===, !=, !==, >, <, >=, <=, and the logical operators &&, ||, ! with if, switch among other commands could be used to create simple of complex rules.

References

  • How does this work when the second document is only a subset of the master? I have this same need but don't think this answers the question. – RelicCross Mar 28 '16 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.