[英]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及更高版本中:
B1:B4
by clicking on cell B1
and dragging down to B4
, so that B1
is the Active Cell B1
并向下拖动到B4
选择单元格B1:B4
,以便B1
是活动单元格 =SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$4, B1))) > 0
=SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$4, B1))) > 0
OK
button OK
按钮。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.