Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8168267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:27:57+00:00 2026-06-06T20:27:57+00:00

Here is the following code-snippet I’m using in my Google Spreadsheet onEdit() function: else

  • 0

Here is the following code-snippet I’m using in my Google Spreadsheet onEdit() function:

else if(editedCell.getColumn() == 13 && editedCell.getRow() == 29) {
    var modVal = sheet.getRange("L29").getValue();

    if(editedCell.getValue() == "Yes") {
      sheet.getRange("G23").setValue(sheet.getRange("G23").getValue() + modVal);
      sheet.getRange("G24").setValue(sheet.getRange("G24").getValue() + modVal);
      sheet.getRange("G25").setValue(sheet.getRange("G25").getValue() + modVal);
      sheet.getRange("G26").setValue(sheet.getRange("G26").getValue() + modVal);
      sheet.getRange("G27").setValue(sheet.getRange("G27").getValue() + modVal);
      sheet.getRange("G28").setValue(sheet.getRange("G28").getValue() + modVal);
      sheet.getRange("G29").setValue(sheet.getRange("G29").getValue() + modVal);
    }
    else if(editedCell.getValue() == "No") {
      sheet.getRange("G23").setValue(sheet.getRange("G23").getValue() - modVal);
      sheet.getRange("G24").setValue(sheet.getRange("G24").getValue() - modVal);
      sheet.getRange("G25").setValue(sheet.getRange("G25").getValue() - modVal);
      sheet.getRange("G26").setValue(sheet.getRange("G26").getValue() - modVal);
      sheet.getRange("G27").setValue(sheet.getRange("G27").getValue() - modVal);
      sheet.getRange("G28").setValue(sheet.getRange("G28").getValue() - modVal);
      sheet.getRange("G29").setValue(sheet.getRange("G29").getValue() - modVal);
    }
}

As you can see, I’m just simply doing each cell manually line by line. Is there a way to specify an array of ranges and then do the math in a simple foreach() type function? I’m not sure how to ask my question, but I believe it’s self-apparent when looking at my code above.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:27:59+00:00Added an answer on June 6, 2026 at 8:27 pm
    var modVal = sheet.getRange("L29").getValue();
    
    // Create a function that updates a given sheet at a given range with
    // the result of a value function
    var changeRangeValue = new function(sheet, range, value) {
        sheet.getRange(range).setValue(value(sheet, range));
    };
    
    var calculateValue;
    
    if(editedCell.getValue() == "Yes") {
        // Create a function that returns a value of a given sheet at a given range with
        // the mod value added
        calculateValue = new function(sheet, range) {
            return sheet.getRange(range).getValue() + modValue; 
        };
    }
    else if(editedCell.getValue() == "No") {
        // Create a function that returns a value of a given sheet at a given range with
        // the mod value added        
        calculateValue = new function(sheet, range) {
            return sheet.getRange(range).getValue() - modValue;
        };
    }
    else {
        // Create a function that returns the current value of a given sheet at a given range
        calculateValue = new function(sheet, range) {
            return sheet.getRange(range).getValue();
        };
    }
    
    // Go through G23-G29 and update the range value with the correct value
    for(var i=23; i <= 29; i++) {
        changeRangeValue(sheet, "G"+i, calculateValue);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code snippet in order to crop a image? function
Going through K&R I saw the following code snippet of a function, strcopy, which
I found the following code snippet here : with TClipper.Create do try AddPolygon(subject, ptSubject);
I am using the following code snippet to create a bitmap with text. Paint
I am inserting an Image in the MediaStore cache using the following code snippet:
I've got the following code snippet. function addLinks () { for (var i=0, link;
I have the following code snippet to enable extension after firefox quit, observe: function
I'm trying to execute a command using the following code snippet: foreach($package in (Get-Childitem
here the following code is used to view the present modal view controller. [[self
I have the following code here that won't run on ARC since it combines

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.