How do I dial only colored cells in GAS?

Asked 2 years ago, Updated 2 years ago, 63 views

There is a behavior that I used to do in Excel's VBA, but the spreadsheet has been changed and it has stopped working.
I've never used GAS, and I don't know how to reproduce what I've done so far...

It means that only cells with a fixed background color in column A ("yellow" in this case) are numbered.
On the VBA,

Dimc As Range, iAs Long
For Each c In Selection
    If c. Interior.ColorIndex=6 Then
        c=c+i+1
        i=i+1
    End if
Next c

Failed to manually select the cell range you want to search for and start the macro.

If anyone knows how to reproduce this behavior with GAS, please let me know.

google-apps-script

2022-09-30 21:31

1 Answers

The behavior can be reproduced by:

function myFunction(){
  varactiveSheet=SpreadsheetApp.getActiveSheet();
  range=activeSheet.getSelection().getActiveRange();
  varbgColors=range.getBackground();
  var values = range.getValues();
  var num = 1;
  for (vari in bgColors) {
    for(varjing bgColors[i]){
      if(bgColors[i][j]==="#ffff00")
        values[i][j] = num++;
    }
  }
  range.setValues(values);
}


2022-09-30 21:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.