没有好的思路,来个暴力的,本来不好意思贴出来的,想了想,贴出来或许会勾引高手来指点一下也说不定
Sub test()
Dim SourceArr, TargetArr(), Mydic1 As Object, Mydic2 As Object
Set Mydic1 = CreateObject("scripting.dictionary")
Set Mydic2 = CreateObject("scripting.dictionary")
SourceArr = [a1].CurrentRegion
ReDim TargetArr(1 To UBound(SourceArr), 1 To UBound(SourceArr, 2))
For i = 1 To UBound(SourceArr)
For j = 1 To UBound(SourceArr, 2)
For x = IIf(j = UBound(SourceArr, 2), i + 1, i) To UBound(SourceArr)
For y = IIf(x = i, j + 1, 1) To UBound(SourceArr, 2)
If Len(SourceArr(i, j)) = Len(SourceArr(x, y)) Then
Z = 0
For k = 1 To Len(SourceArr(i, j))
Mydic1(Mid(SourceArr(i, j), k, 1)) = 0
Mydic2(Mid(SourceArr(i, j), k, 1)) = 0
Next
For k = 1 To Len(SourceArr(i, j))
Mydic1(Mid(SourceArr(i, j), k, 1)) = Mydic1(Mid(SourceArr(i, j), k, 1)) + 1
Next
For k = 1 To Len(SourceArr(x, y))
Mydic2(Mid(SourceArr(x, y), k, 1)) = Mydic2(Mid(SourceArr(x, y), k, 1)) + 1
Next
For k = 1 To Len(SourceArr(i, j))
If Mydic1(Mid(SourceArr(i, j), k, 1)) = Mydic2(Mid(SourceArr(i, j), k, 1)) Then Z = Z + 1
Next
If Z = Len(SourceArr(i, j)) Then TargetArr(x, y) = 1
End If
Next
Next
Next
Next
'测试用,只是标注,没有删除
For i = 1 To UBound(TargetArr)
For j = 1 To UBound(TargetArr, 2)
If TargetArr(i, j) = 1 Then Cells(i, j).Interior.Color = 255
Next
Next
End Sub
|