|
比葫芦画瓢 弄个函数 哈哈
Public Function A独有(A, B) 'A中有B中没有的内容。A,B只能是列不能是行。且结果不去除A中的重复值,若需去除重复值,可配合unique函数使用
Dim arr, BRR, d As Object, i As Long, m As Long, ZR()
arr = B
Set d = CreateObject("scripting.dictionary")
For i = 1 To UBound(arr)
d(arr(i, 1)) = ""
Next i
BRR = A
ReDim ZR(1 To UBound(BRR), 1 To 1)
m = 0
For i = 1 To UBound(BRR)
If Not d.exists(BRR(i, 1)) Then
m = m + 1
ZR(m, 1) = BRR(i, 1)
End If
Next i
A独有 = 非空(ZR)
Set d = Nothing
End Function
Public Function AB共有(A, B) 'A中AB中都有的值。可配合unique函数去重,求得AB交集
Dim arr, BRR, d As Object, i As Long, m As Long, ZR()
arr = B
BRR = A
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
d(arr(i, 1)) = ""
Next i
ReDim ZR(1 To UBound(BRR), 1 To 1)
m = 0
For i = 2 To UBound(BRR)
If d.exists(BRR(i, 1)) Then
m = m + 1
ZR(m, 1) = BRR(i, 1)
End If
Next i
AB共有 = 非空(ZR)
Set d = Nothing
End Function
Public Function 非空(A)
Dim arr, k As Long, BRR, l As Long, n As Long
arr = A
For k = UBound(arr) To 1 Step -1
If arr(k, 1) <> "" Then
l = k
ReDim BRR(1 To l, 1 To 1)
For n = 1 To l
If arr(n, 1) <> "" Then
BRR(n, 1) = arr(n, 1)
Else: BRR(n, 1) = " "
End If
Next n
非空 = BRR
Exit For
End If
Next k
End Function
|
|