Reputation: 55
So here is a bit of the code that retrieves data from a list where dates may or may not be inputted. If there is a date, the month will be extracted, and based on what month it is, I want the cell (17,4 in this case) to count how many dates of that month. The loop goes through the page to pull out all the dates but I do not know how to count or add more than one to (17,4).
for(var i =8;i<=j;i++) {
var dates = oppwon.getRange(i,22).getValue();
var tiers = oppwon.getRange(i,14).getValue();
var month = new Date(dates).getMonth();
switch (true){
case((month==1)):
if(tiers==1)
{summary.getRange(17,4).setValue()+1;}
break;
Upvotes: 0
Views: 54
Reputation: 201713
getRange(17,4)
) when month == 1
and tiers == 1
.If my understanding is correct, how about this modification? Please think of this as just one of several answers
Please modify your script as follows.
From:for(var i =8;i<=j;i++) {
var dates = oppwon.getRange(i,22).getValue();
var tiers = oppwon.getRange(i,14).getValue();
var month = new Date(dates).getMonth();
switch (true){
case((month==1)):
if(tiers==1)
{summary.getRange(17,4).setValue()+1;}
break;
To:
var range = summary.getRange(17,4); // Added
var currentValue = range.getValue(); // Added
for (var i = 8; i <= j; i++) {
var dates = oppwon.getRange(i,22).getValue();
var tiers = oppwon.getRange(i,14).getValue();
var month = new Date(dates).getMonth();
switch (true) {
case (month == 1):
if (tiers == 1) {
range.setValue(++currentValue); // Modified
}
break;
1
.getValue()
in the for loop leads to the high process cost. But I'm not sure about your whole script. So I couldn't propose about this.If I misunderstood your question and this was not the result you want, I apologize. At that time, can you provide the sample Spreadsheet and your script for replicating your issue. By this, I would like to confirm it.
Upvotes: 1