Returning row values based on specific variables across multiple sheets

0

I'm not entirely sure how to properly explain this, but here we go...

I'm trying to create a single budgeting document that allows me to manage purchasing and reconciliation for multiple projects. I would like to create separate sheets per project and have purchased items populate on a master sheet.

Using conditional formatting, I've set one of the columns to display an item's status (waiting for approval, approved, ordered, received). I would like the contents of an entire row to populate in a new sheet table once the status is set to "Received." The sheet should update descendingly.

screenshot

Any help is greatly appreciated.

Mike Bodes

Posted 2014-05-29T01:05:46.690

Reputation: 3

Mike, for the most part it sounds like everything you want to do is achievable, and with simple excel formulas. In lieu of a picture, can you give us an example of the project worksheet and an example of the master sheet? All I'm looking for is the column headings and an example row. If the data format is not uniform, just provide the format of the data you want. Also provide a reference for where the data is starting (ie first cell is A1) – N8sBug – 2014-05-29T09:39:16.313

@N8sBug Thanks for the response. Having trouble formatting in the comment. I took a screen shot using some dummy data that should be helpful:

https://lh4.googleusercontent.com/-2urKIld6n0M/U4cyuqI8UEI/AAAAAAAAD9Q/0KGB5B_ZeM4/w2174-h542-no/Spreadsheet1.png

– Mike Bodes – 2014-05-29T13:16:18.843

Mike, thanks for this. Because of the way you want to do this, I think a macro would be best suited for it. However, it looks like you might be using google spreadsheets is that correct? – N8sBug – 2014-05-29T13:19:31.733

The reason I ask is that the scripts will be radically different if google spreadsheets is the intended target application to run the calculation. – N8sBug – 2014-05-29T13:31:46.763

@N8sBug that's correct, I would like to use Google Spreadsheets if possible because the document is shared and updated by my team. If this function isn't possible in Google Spreadsheets, I could use Excel. Thanks for your help with this. – Mike Bodes – 2014-05-29T14:53:04.540

It's been a few days, and I just wanted to find out if you had any luck with this issue... – N8sBug – 2014-06-04T15:49:50.757

@N8sBug Hey, sorry for the delayed response, but yes, the script you provided is working nicely! I had an issue with the Google document (It was not saving changes), so tried waiting a few days to see if the error would stop.. No avail, so I created a new doc and added your script. Just one questions, am I able to populate the first 4 rows as the header for the page? Each project sheet has a header that is 4 rows. Thanks again for all of your help with this, much appreciated! – Mike Bodes – 2014-06-12T16:40:48.213

Rows or first four cells in row A?? I think you can add what ever you want for each new project so long as it doesn't say "Received" in column H. Just note, that the header row for the master sheet comes from the first project in the sheet. – N8sBug – 2014-06-12T16:45:29.153

@N8sBug first four rows, not just the cells in row A. Answer accepted! – Mike Bodes – 2014-06-12T17:21:07.443

Answers

0

After reviewing your question a little closer, I determined that you would need to write a google script to accomplish this.

All you need to do is: open up the google script editor, make a new project, paste this in the bottom of the script, rename the "Reconciliation" to be whatever the name of your spreadsheet is, and then save it. The onEdit() is a trigger built into google scripts that does the work of updating after an edit, and the checkReceived() is a hand rolled example that does the work you seek. I tailored this "example" to your image provided. You will see that you can add as many projects as you want and this will cover them just the same. You can change the particulars to match whatever else you need (ie you should also note that I called the master sheet "Master"), but this should work for you. Please let me know how it goes.

function checkReceived() {


  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

  //The following to ensures you don't run this on another spreadsheet
  if(spreadsheet.getName()=="Reconciliation") //<--This is the name of the spreadsheet I used, change it for yours.
  {  

    var maxIntervalSS = spreadsheet.getNumSheets();
    var theMasterSheet = spreadsheet.getSheetByName("Master");
    var masterSheetID = theMasterSheet.getIndex();
    var sheets = spreadsheet.getSheets();
    var thisRow = theMasterSheet.getRange(1,1); //Arbitrary for initialization

    //Need to Clear existing master data.
    theMasterSheet.getDataRange().clear();

    //Will use a flag to repopulate header.
    var firsttime= true;

    //Iterates through each spreadsheet
    for(var checkingSheetIterator = 0; checkingSheetIterator<maxIntervalSS; checkingSheetIterator++)
    {

      var currentSheet = sheets[checkingSheetIterator];

      //Ignores the iteration if ID equals the master sheet
      if(currentSheet.getIndex()!=masterSheetID)
      {




        //Getting currentSheet's data
        var currentRange = currentSheet.getDataRange();

        //Iterates through the currentSheet's data
        for(var rows = 1; rows<=currentSheet.getLastRow(); rows++)
        {
          //Repopulating header on first time.              
          //"8" for column H, containing the Status
          if(currentRange.getCell(rows,8).getValue()=="Received"|| firsttime)  //<-Note this is your keyword and specified location; "8".
          {  //Add to bottom of sheet
            theMasterSheet.appendRow([currentRange.getCell(rows,1).getValue(),currentRange.getCell(rows,2).getValue(),
                                      currentRange.getCell(rows,3).getValue(),currentRange.getCell(rows,4).getValue(),
                                      currentRange.getCell(rows,5).getValue(),currentRange.getCell(rows,6).getValue(),
                                      currentRange.getCell(rows,7).getValue(),currentRange.getCell(rows,8).getValue(),
                                      currentRange.getCell(rows,9).getValue(),currentRange.getCell(rows,10).getValue(),
                                      currentRange.getCell(rows,11).getValue()]);
            firsttime=false;
          }
        }
      }
    }
  }
};  

function onEdit(){

  checkReceived();

};

The following is an example of the spreadsheet setup. Notice the name of the spreadsheet is Reconciliation (top of the picture), and the tabs (ie sheets) at the bottom of the page are named "Master", "Project1", and "Project2". Please note, that I didn't bother with the conditional formatting as it shouldn't have any bearing on the outcome. enter image description here

N8sBug

Posted 2014-05-29T01:05:46.690

Reputation: 204

Thanks so much. I'll give this a shot and let you know how it goes! – Mike Bodes – 2014-05-30T18:37:44.263

No problem! Again, just remember to edit the sheet name(I used "Master") to match the sheet name of you master sheet, and to replace the spreadsheet's name (I used "Reconciliation") with your spreadsheet name. – N8sBug – 2014-05-30T18:40:05.227

If I'm pulling multiple spreadsheets into that Master sheet, can I add them into this expression: if(spreadsheet.getName()=="Reconciliation")?

I.e. if(spreadsheet.getName()=="Reconciliation", "Sheet2", "Sheet3") – Mike Bodes – 2014-05-30T18:43:50.207

So, we need to be clear about terminology. Are you talking about adding in new individual sheets, or are you implying that are going to copy and paste tables of data into the master sheet? Or using this function on separate collections of sheets (in excel they are called "Books")? If you use this function on new Spreadsheets, you will need to make sure the master sheet is named the same as your original. – N8sBug – 2014-05-30T18:50:54.127

I added a photo to be clear about what is going on. I believe this is how you are doing it. One sheet (ie "Project1) per project and a master (ie "Master") sheet that summarizes the received orders. Please let me know if this is not what you meant. – N8sBug – 2014-05-30T19:14:22.043

That's correct, your photo depicts exactly what I'm looking for. Edits would be made in Project1 and Project2, then the Master sheet would auto-populate accordingly. – Mike Bodes – 2014-05-30T20:24:02.210

So to your question earlier, are you thinking of applying this function to other spreadsheets (ie "Reconciliation" and "Reconciliation2")? If so, the context would need to be something like: if(spreadsheet.getName()=="Reconciliation"||spreadsheet.getName()=="Reconciliation2") Otherwise, if you are just adding sheets, there is nothing you need to do. You may have to select a cell once, as though to edit it, to kick off the onEdit() function, but there should be no code change requried for adding new sheets to the spreadsheet/workbook. – N8sBug – 2014-05-30T20:25:30.507