79717697

Date: 2025-07-28 17:43:09
Score: 1.5
Natty:
Report link

I was not able to pull this strictly using google app script on account of being a novice, but did have a workaround using a combination of functions and script.

For each filterable column criteria needed on the sheet I matched resulting column numbers with arrayformulas, then matched them against against themselves to limit my column range.

Filter_Job_Return = arrayformula(filter(COLUMN(Job_Names_Range),Job_Names_Range=Job))

Filter_Date_Return = arrayformula(filter(COLUMN(Date_Support_Range),Date_Support_Range>=Date_Range_Beginning,Date_Support_Range<=Date_Range_End))

Filter_Columns_Match = ARRAYFORMULA(text(FILTER(Filter_Job_Return_Range,ISNUMBER(MATCH(Filter_Job_Return_Range,Filter_Date_Return))),"0"))

For the variable row I needed I did a similar filter to return the row number for that employee, though a similar matching logic of the columns can be adapted to rows to remove potential duplicates

Example:

Need: Job# 4, Between Dates 01/15/20xx and 03/15/20xx, Employee Name: Joe

Update Projected Hours to 15

Labels Col 2 Col 3 Col 4 Col 5
Job_Return 2 4 4 6
Date_Return 01/01/20xx 02/01/20xx 03/01/20xx 04/01/20xx
Columns_Match 3 4
Row_Return 6
Employee Names Projected Hours Projected Hours Projected Hours Projected Hours
Joe 10 10 10 10

Macro to Replace selected values:

function ReplaceProjectedHours(){
  const ss = SpreadsheetApp.getActive();
  let sheet = ss.getSheetByName("Projected Hours"); //pulls from sheet by name
  const projectedHoursPerWeek = ss.getRangeByName("Projected_Hours_per_Week").getValues();
  let row = ss.getRange("B4").getDisplayValue(); //pulls cell from upper left corner of spill array formula if multiple results are given
  let colArray = ss.getRangeByName("Filter_Columns_Match").getDisplayValues();

  //Logger.log("colArray.length:" + colArray.length);
  //Logger.log(colArray);

//https://stackoverflow.com/questions/61780876/get-x-cell-in-range-google-sheets-app-script
  for(let j = 0; j < colArray[0].length; j++) {
    if (colArray[0][j] !== "") { // Check if the cell is not empty
      sheet.getRange(row, colArray[0][j]).setValues(projectedHoursPerWeek); //sets values based on position in array of object
    }
  }
}
Labels Col 2 Col 3 Col 4 Col 5
Job_Return 2 4 4 6
Date_Return 01/01/20xx 02/01/20xx 03/01/20xx 04/01/20xx
Columns_Match 3 4
Row_Return 6
Employee Names Projected Hours Projected Hours Projected Hours Projected Hours
Joe 10 15 15 10

And the macro replaces the match cells over non-continuous ranges based on the matching criteria

Reasons:
  • Blacklisted phrase (0.5): I need
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Cog