比较两列,如果文本包含第一列的文本,则突出显示该文本

我有两列

A | B -------------------------------------- 123 main street | 123 234 cello street | 456 449 w 3rd street | 585 1098 folsom blvd | 1098 2323 new york street | 1088 676 cherry street | 676 

我的问题是,是否有机会比较列A和列B,如果列B的值在列A中,我们不是比较整个文本,而只是列A的一部分与整个列B的比较。

*注意:*我确定B列中两个单元格的组合不会出现在A中,例如,列A中不会出现123456。

 =IF(SEARCH(B1;A1;1);1;0) 

如果文本存在,会得到1,如果不是,则为0。 那是你要的吗?

这可能不是最高性能的方式,但是有一个方便的VBAfunction可以将范围转换为CSV,并且在这里。 (按Alt + F11键以访问VBA开发人员,并将其放入新模块中):

 '********************************************** '* PURPOSE: Concatenates range contents into a '* delimited text string '* '* FUNCTION SIGNATURE: Range2Csv(Range, String) '* '* PARAMETERS: '* Range - the range of cells whose contents '* will be included in the CSV result '* String - delimiter used to separate values '* (Optional, defaults to a comma) '* '* AUTHOR: www.dullsharpness.com '********************************************** Public Function Range2Csv(inputRange As Range, Optional delimiter As String) Dim concattedList As String 'holder for the concatted CSVs Dim rangeCell As Range 'holder cell used in For-Each loop Dim rangeText As String 'holder for rangeCell's text 'default to a comma delimiter if none is provided If delimiter = "" Then delimiter = "," concattedList = "" 'start with an empty string 'Loop through each cell in the range to append valid contents For Each rangeCell In inputRange.Cells rangeText = rangeCell.Value 'capture the working value 'Only operate on non-blank cells (ie Length > 0) If Len(rangeText) > 0 Then 'Strip any delimiters contained w/in the value itself rangeText = WorksheetFunction.Substitute(rangeText, delimiter, "") If (Len(concattedList) > 0) Then 'prepend a delimiter to the new value if we 'already have some list items concattedList = concattedList + delimiter + rangeText Else 'else if the list is blank so far, 'just set the first value concattedList = rangeText End If End If Next rangeCell 'Set the return value Range2Csv = concattedList End Function 

假设您要search的范围是A1:A20 ,则可以突出显示search项单元格(从本例中的单元格B1开始),并input以下条件格式公式:

 =ISNUMBER(FIND(B1,range2csv($A$1:$A$20,";"))) 

这将通过首先制作所有search目标(将每个单元格连接成一个连续string)的string,然后逐个检查连接string中是否存在search项(列B条目)。

如上所述,这可能不是执行此操作的最高性能方式,但这是一个快速解决scheme。

Range2Csv函数写入