繁体   English   中英

如何突出显示两个Excel单元格,每个单元格中包含多个单词

[英]How to highlight two excel cells contain multiple words in each cell

这可能有点难以解释,但我将使用以下示例

在此处输入图片说明

如您所见,excel工作表有两列(C和F),我能够使用条件格式来突出显示绿色的重复单元格。 我想知道如何将包含多个单词的两个不同单元格的每个单元格至少保留一个单词,因为您可以看到黄色的单元格。 谢谢

您可以使用下面的UDF比较值

Public Function comparecells(cell1 As String, cell2 As String) As Boolean

'store words of each cells in two diffrent arrays

    array1 = Split(cell1, " ")
    array2 = Split(cell2, " ")

    'reset the function value
    comparecells = False

    'check each word from one array against the other
    For Each Value1 In array1
        For Each Value2 In array2
            If Value1 = Value2 Then
                'If it finds any match set function return value to true and exit
                comparecells = True
                Exit Function
            End If
        Next Value2
    Next Value1

End Function

这是条件格式的公式,如果至少一个单词匹配,它将返回TRUE。

这是为单元格C2写的,并且假定它正在寻找单元格F2至F15中的值。

=NOT(ISERROR(LOOKUP(2^15,SEARCH(TRIM(MID(SUBSTITUTE(" "&C2," ",REPT(" ",99)),{1,2,3}*99,99)),F2:F15,1),F2:F15)))

调整使其适合。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM