I'm currently facing an issue where I need to change the cell color of multiple cells at once, all stored within a specific range. However, I only want certain cells to change based on a particular condition. While I can manually change each cell, it's time-consuming and inefficient. I am thinking that if I can construct a range of cells, I could use the setBackground() command for better efficiency.
Therefore, I'm seeking advice on the most effective way to tackle this problem?
The approach I am considering involves:
- Utilizing a range.
- Recognizing that ranges contain a "block" of cells, including some that may not require color changes.
- Exploring the possibility of removing unwanted cells from a range. If achievable, I could iterate through and exclude those unnecessary cells before applying changes to the rest.
- Potentially storing cells in an array and creating a range from that. However, this idea is hindered by my understanding that ranges typically consist of a rectangular block with two corner cells and contents in between.
- Investigating alternative constructs that can handle multiple cells simultaneously, akin to a range’s capabilities.
Here is my current loop logic:
for(var i=1; i<=numRows; i++){
for(var j=1; j<=numColumns; j++){
var mCell = monthRange.getCell(i, j);
var mValue = mCell.getValue();
if(mValue != "")
{
var eCell = exerciseRange.getCell(1, mValue);
var eValue = eCell.getValue();
}
if (mValue != "" && eValue == true) {
mCell.setBackground('green');
}
}
}
I would greatly appreciate any assistance as I navigate this challenge, especially since I am relatively new to this concept.
Thanks! TM