[英]I want to use conditional formatting to highlight a cell in one column if the corresponding line in another column contains a specific value
[英]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
您可以使用條件格式來完成此操作。 在Excel 2007及更高版本中:
B1
並向下拖動到B4
選擇單元格B1:B4
,以便B1
是活動單元格 =SUMPRODUCT(--ISNUMBER(SEARCH($A$1:$A$4, B1))) > 0
OK
按鈕。
結果:
您可以使用VBA /宏來完成此操作。 對於您的示例,請按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.