So I am trying to run a script in Google Sheets. I have two sheets, one of which is a master list with all of my data and another of which is a sheet I am using to filter results when I want to look through a specific date/category. I'm doing this by having three cells in my filtering sheet that I would fill out information to match up with the master list and then having a button that would copy the data over. Here is my code:
function filter() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Total");
var month = ss.getSheetByName("Filter").getRange("A2").getValue();
var payment = ss.getSheetByName("Filter").getRange("B2").getValue();
var category = ss.getSheetByName("Filter").getRange("C2").getValue();
for(var i = 1; i < 200; i++)
{
var p = s.getRange(i, 5);
var c = s.getRange(i, 6);
var m = s.getRange(i, 7);
if( p.getValue() == payment && c.getValue() == category && m.getValue()
== month){
var targetSheet = ss.getSheetByName("Filter");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(i, 1, 1, 7).copyTo(target);
}
}
}
Using &&
conditional inside of my if statement results in nothing appearing. Using ||
conditional results in everything appearing. I can't seem to figure out how to make it so that I can sort by just one category OR all categories.
Thanks in advance!