Easiest Way is to NAME your Trigger Range
By naming your "trigger" range, then you don't have to mess with the script once you've set the range name inside the script. By simply editing the range of your named range inside the standard google sheets interface, the script will still work even if you expand or decrease the size of your range.
Step 1: Name Your Range
Name the range of cells you are interested in acting as the trigger for your script should you edit any of the cells in your range as per the instructions here: https://support.google.com/docs/answer/63175
I named my range "triggerRange".
Step 2: Edit your range name into the following script:
function onEdit(e) {
var myRange = SpreadsheetApp.getActiveSheet().getRange('triggerRange');
var row = e.range.getRow();
var col = e.range.getColumn();
if (col >= myRange.getColumn() && col <= myRange.getLastColumn() && row >= myRange.getRow() && row <= myRange.getLastRow()) {
SpreadsheetApp.getUi().alert('You Edited a Cell INSIDE the Range!');
} else {
SpreadsheetApp.getUi().alert('You Edited a Cell OUTSIDE the Range!');
return;
}
}
PS: Thanks to the other posters for providing the basic framework for this basic script. I've obviously commented the script pretty heavily so you can easily test it. Remove the alerts that I created inside the script for a cleaner look...or just copy and paste this instead:
function onEdit(e) {
var myRange = SpreadsheetApp.getActiveSheet().getRange('triggerRange');
var row = e.range.getRow();
var col = e.range.getColumn();
if (col >= myRange.getColumn() && col <= myRange.getLastColumn() && row >= myRange.getRow() && row <= myRange.getLastRow()) {
SpreadsheetApp.getUi().alert('You Edited a Cell INSIDE the Range!');
}
}