|
- Dim objDic As Object
- Dim objDic2 As Object
- Dim Arr, Arr2, Arr3
- Dim strBeginValue$
- Dim strEndValue$
- Dim intLength%
- Dim boolCheck As Boolean
- Dim strValue$
- Arr = Sheets("匹配数据").[a1].CurrentRegion
- Arr2 = Sheets("需求匹配结果").[a1].CurrentRegion
- ReDim Arr3(1 To UBound(Arr2))
- Set objDic = CreateObject("scripting.dictionary")
- For i = 2 To UBound(Arr)
- strBeginValue = Arr(i, 1)
- strEndValue = Arr(i, 2)
- If Not objDic.exists(strBeginValue) Then
- Set objDic(strBeginValue) = CreateObject("scripting.dictionary")
- End If
- If Not objDic(strBeginValue).exists(strEndValue) Then
- objDic(strBeginValue)(strEndValue) = strEndValue
- End If
- Next
- For i = 2 To UBound(Arr2)
- strBeginValue = Arr2(i, 1)
- strEndValue = Arr2(i, 2)
- intLength = Len(strEndValue)
- For j = intLength To 1 Step -1
- strValue = Left(strEndValue, j)
- If objDic(strBeginValue).exists(strValue) Then
- Arr3(i) = strValue
- boolCheck = True
- Exit For
- End If
- Next
- If boolCheck = False Then
- Arr3(i) = strEndValue
- Else
- boolCheck = False
- End If
- Next
- [d1].Resize(UBound(Arr3), 1) = Application.Transpose(Arr3)
复制代码 |
|