<p>Sub 唯一值()<br/>Dim x, y, z<br/>Dim arr1, arr2, arr3<br/>Range("d2:D" & Range("D65536").End(xlUp).Row + 1) = ""</p><p>arr1 = Range("A2:A11")<br/>arr2 = Range("B2:B11")<br/>ReDim arr3(1 To UBound(arr1, 1) + UBound(arr2, 1), 1 To 1)<br/>For x = 1 To UBound(arr1)<br/> arr3(x, 1) = arr1(x, 1)<br/>Next x<br/>For z = 1 To UBound(arr2, 1)<br/>For y = 1 To UBound(arr1, 1)<br/> If arr2(z, 1) = arr1(y, 1) Then GoTo 100<br/> Next y<br/> k = k + 1<br/> arr3(x + k - 1, 1) = arr2(z, 1)<br/>100:<br/>Next z<br/>Range("d2").Resize(k + x) = arr3</p><p>End Sub</p><p>----------------------------------------------------------------------------------------<br/>Sub 物品1有物品2没有()<br/>Dim x, y, z<br/>Dim arr1, arr2, arr3<br/>Range("E2:E" & Range("E65536").End(xlUp).Row + 1) = ""</p><p>arr1 = Range("A2:A11")<br/>arr2 = Range("B2:B11")<br/>ReDim arr3(1 To UBound(arr1, 1), 1 To 1)<br/>For x = 1 To UBound(arr1)<br/>For y = 1 To UBound(arr2, 1)<br/> If arr2(y, 1) = arr1(x, 1) Then GoTo 100<br/> Next y<br/> k = k + 1<br/> arr3(k, 1) = arr1(x, 1)<br/>100:<br/>Next x<br/>Range("E2").Resize(k) = arr3</p><p>End Sub</p><p>--------------------------------------------------------------------------------------------------</p><p>Sub 物品2有物品1没有()<br/>Dim x, y, z<br/>Dim arr1, arr2, arr3<br/>Range("F2:F" & Range("E65536").End(xlUp).Row + 1) = ""</p><p>arr1 = Range("A2:A11")<br/>arr2 = Range("B2:B11")<br/>ReDim arr3(1 To UBound(arr2, 1), 1 To 1)<br/>For x = 1 To UBound(arr2)<br/>For y = 1 To UBound(arr1, 1)<br/> If arr1(y, 1) = arr2(x, 1) Then GoTo 100<br/> Next y<br/> k = k + 1<br/> arr3(k, 1) = arr2(x, 1)<br/>100:<br/>Next x<br/>Range("F2").Resize(k) = arr3</p><p>End Sub</p>
[此贴子已经被作者于2008-1-13 21:28:16编辑过] |