Reputation: 13
I have two columns of checkboxes in a Google Sheets document (column A
and column B
, for example sake), and I want to be able to add a function that will look down column A
, and move any checked boxes into column B
, while ignoring any rows where the cell in column A
is blank. I intend to add this function into a drop down menu in in my spreadsheet.
So, as an illustration:
Sheet before running this function:
Column A | Column B
=====================
✓ | ☐
✓ | ☐
☐ | ☐
☐ | ✓
---
Sheet after running this function:
Column A | Column B
=====================
☐ | ✓
☐ | ✓
☐ | ☐
☐ | ✓
I've figured out how to check or uncheck whole ranges, so I can clear column A
easy enough, but I can't figure out what to do to change those specific cells in column B
where column A
is checked first.
Upvotes: 1
Views: 228
Reputation: 64110
Try this:
function runTwo() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Sheet2');
var rg=sh.getDataRange();
var vA=rg.getValues();
for(var i=0;i<vA.length;i++) {
if(vA[i][0] && vA[i][0]==true) {
vA[i][0]=false;
vA[i][1]=true;
}
}
rg.setValues(vA);
}
Upvotes: 2