简体   繁体   English

我试图找到一个公式,如果它包含位于另一列中的任何单词,可以突出显示一列中的单元格

[英]I am trying to find a formula that can highlight a cell in one column if it contains any of the words located in another column

Column A contains US Cities, one city per cell, going down the column. A列包含美国城市,每个单元格一个城市,沿着列向下。

Column B contains sentences that may or may not contain one of the cities mentioned in Column A. B栏包含的句子可能包含也可能不包含A列中提到的某个城市。

I would like to have Column B highlighted if it contains any of the cities mentioned in column A. 如果它包含A列中提到的任何城市,我想要突出显示B列。

Note: There will be other text besides the city name in the cells. 注意:单元格中除城市名称外还有其他文本。

Here is a sample of what it would look like without anything highlighted 这是一个没有突出显示任何内容的样子

在此输入图像描述

Everything in column B should be highlighted except "from xyz" 除了“来自xyz”之外,列B中的所有内容都应突出显示

You can accomplish this by using Conditional Formatting. 您可以使用条件格式来完成此操作。 In Excel 2007 and later: 在Excel 2007及更高版本中:

  1. Select cells B1:B4 by clicking on cell B1 and dragging down to B4 , so that B1 is the Active Cell 通过单击单元格B1并向下拖动到B4选择单元格B1:B4 ,以便B1活动单元格
  2. Click Home -> Conditional Formatting -> New Rule... 单击主页 - >条件格式 - >新规则...
  3. In the New Formatting Rule dialog, select the Use a formula to determine which cells to format option 在“ 新建格式规则”对话框中,选择“ 使用公式确定要格式化的单元格”选项
  4. In the Format values where this formula is true textbox, enter the following: =SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$4, B1))) > 0 此公式为true格式值文本框中,输入以下内容: =SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$4, B1))) > 0
  5. Click the Format... button 单击格式...按钮
  6. In the Format Cells dialog, set your desired formatting options (eg select the yellow color on the "Fill" tab), and click the OK button 在“ 单元格格式”对话框中,设置所需的格式选项(例如,在“填充”选项卡上选择黄色),然后单击“ OK按钮。
  7. In the New Formatting Rule dialog, click the OK button 在“ 新建格式规则”对话框中,单击“ 确定”按钮


Result: 结果:

在此输入图像描述

You can do this by using VBA/Macros. 您可以使用VBA /宏来完成此操作。 For your example, press Alt+F11 , then insert module and put this macro code: 对于您的示例,请按Alt+F11 ,然后插入模块并放置此宏代码:

Sub highlight()
Dim n As Integer, strng As String
Dim LastRow As Long
    Columns("B:B").Select
    n = 1
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With

    For n = 1 To LastRow
        strng = "=$A$" & n
        Selection.FormatConditions.Add Type:=xlTextString, String:=strng, _
            TextOperator:=xlContains
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 13551615
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    Next n
End Sub

Here is an example file you can check. 是您可以检查的示例文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果另一列中的相应行包含特定值,我想使用条件格式突出显示一列中的单元格 - I want to use conditional formatting to highlight a cell in one column if the corresponding line in another column contains a specific value 无法找到合适的公式来将一列中的单词部分匹配到另一列 - Unable to find a proper formula to partially match words in one column to another 用于在包含另一列中的某个值的列中查找下一个值的公式 - Formula to Find Next Value in a Column that Contains a Certain Value in another Column 如果Excel中包含的单词位于另一列中,如何在Excel中突出显示单元格 - How to highlight a cell in Excel if the word it contains is in another column 尝试突出显示一列中值与另一列重复的实例 - Trying to highlight instances in one column where the value is duplicated in another column 如何在一个列中找到一个短语,然后将另一个短语输出到另一个单元格中 - How can I find a phrase in one column, and output another phrase into a different cell excel公式:根据另一列的值在一个列中查找唯一性 - excel formula : Find uniques in one column depending on value of another column Excel条件格式,如果列A包含任何值高亮显示列B中的相邻单元格 - Excel Conditional Formatting If Column A Contains ANY Value Highlight Adjacent Cell In Column B Excel公式在列中找到val并添加到另一个单元格 - Excel formula to find val in column and add to another cell 是否有公式可以从列中列出的单元格中删除单词? - Is there a formula to remove words from a cell that are listed in a column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM