Google Sheet 如果一列包含 5 列的某些文本,则条件格式突出显示 2 列

Google Sheet Conditional Formatting highlight 2 columns if one column contain certain text of 5 columns

在 Google Sheet 中,我想 仅突出显示 5 列中的 2 列。

这里有 5 列,但我想 highlight only 'Name' and 'Weight' columns if a cell contain the word 'Smith'

结果应该是 this.
我想输入更多名称,如果名称包含 'Smith' 这个词,我希望它在名称和重量列中自动突出显示。

我尝试在 Google sheet 中使用条件格式,但我只能突出显示名称列。
这是我试过的。

结果是这样的。

你已经不远了,在条件格式中试试下面的公式:

=IF(REGEXMATCH($C3, "Smith"), 1, 0)

您可以试试下面的代码:

function highlight() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var data = ss.getRange('A1:E').getValues();
  for (i = 1; i < data.length; i++) {
    var tf = ss.getRange("B" + i).createTextFinder('smith');
    tf.matchEntireCell(false);
    tf.matchCase(false);
    var result = tf.findNext();
    if (result !== null) {
      var range = result.getRow();
      ss.getRange('B' + range).setBackground('Yellow');
      ss.getRange('D' + range).setBackground('Yellow');
    }
  };
};

@nabais 给出的公式有效。

在条件格式中虽然不需要使用起始 IF 函数。

“格式单元格 if” 是条件格式规则的默认形成方式,如 official help page 中所述。

  1. Create a rule.
  • Single color: Under "Format cells if," choose the condition that you want to trigger the rule. Under "Formatting style, choose what the cell will look like when conditions are met.
  • Color scale: Under "Preview," select the color scale. Then, choose a minimum and maximum value, and an optional midpoint value. To choose the value category, click the Down arrow Down Arrow.

所以只需要下面的公式:
(请根据您的需要调整范围)

=REGEXMATCH($G2, "Smith")