调整VBA模块以查找部分匹配而不是完全匹配

原始模块在寻找完全匹配时很有用,但现在我需要find部分匹配。

例如,在CompareRange中可能有一个93472398742398-118的值,但是在select内的某个值只有93472398742398。CompareRange是几千行,select要小得多。

我在这里find原始公式: 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 

我也尝试调整一个公式,我发现堆栈溢出答案之一:

确定列表A中的名称是完美匹配,部分匹配还是在列表B中找不到?

但Excel表示公式中有一个错误。

 =MATCH(FALSE;ISERROR(SEARCH(B1;A1:A100));0) 

Interesting Posts