根据另一个单元格的背景色设置单元格的背景色 [英] Setting background colour of cell based on another cell's background colour

查看:99
本文介绍了根据另一个单元格的背景色设置单元格的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有上图所示的工作表,并希望执行以下操作:对于B2:B21和D2:D21范围内的单元格,我想将每个单元格的背景色设置为其右侧邻居的背景色.因此,例如,B3的背景颜色应与C3的颜色相同;D14的背景颜色应与E14的颜色相同,依此类推.是否可以使用Google表格的公式,条件格式设置,还是必须添加脚本来执行此操作?如果可以,怎么办?

I have the sheet shown in the above image and would like to do the following: for the cells in the range B2:B21 and D2:D21 I would like to set each cell's background colour to the background colour of their right neighbour. So, for example, the background colour of B3 should be the same as the colour of C3; the background colour of D14 should be the same as the colour of E14 and so on. Is this possible using Google Sheet's formulas, conditional formatting, or must I add a script to do this, and if so, how?

推荐答案

也许您可以尝试以下方法:

Maybe you can try this:

function changeBackgroundColor() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var cRange = sheet.getRange("C2:C21");
  var cbgColors = cRange.getBackgrounds();
  var bRange = sheet.getRange("B2:B21");
  bRange.setBackgrounds(cbgColors);
  var eRange = sheet.getRange("E2:E21");
  var ebgColors = eRange.getBackgrounds();
  var dRange = sheet.getRange("D2:D21");
  dRange.setBackgrounds(ebgColors);
}

这篇关于根据另一个单元格的背景色设置单元格的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆