原始模块在查找完全匹配时很有用,但现在我需要找到部分匹配。
例如,在CompareRange中,可能有一个值为93472398742398-118,但在选择范围内的某个值仅为93472398742398. CompareRange为几千行,选择范围要小得多。
我在这里找到了原始公式:http://support.microsoft.com/kb/213367。
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Range("F1:F5126")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("F1:F5126")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub
我还尝试调整我在其中一个Stack Overflow答案中找到的公式:
Determine if name in list A has perfect match, partial match, or is not found in list B?
但Excel表示公式中存在错误。
=MATCH(FALSE;ISERROR(SEARCH(B1;A1:A100));0)