1
我有一個接近工作但不完全的代碼。我有兩個數組astrArray1和astrArray2,函數findUniques()應該返回兩個數組中的唯一字符串(名稱)。我可以讓代碼返回它們共有的名稱,但它不會爲唯一的名稱返回正確的值。任何幫助,將不勝感激!從兩個字符串數組中返回唯一字符串,連接成一個字符串VBA
下面是代碼:
Function findUniques(astrArray1() As String, astrArray2() As String) As String
Dim blnMP5 As Boolean
blnMP5 = True
Dim counter1 As Long
Dim counter2 As Long
Dim uniquesString As String
uniquesString = " "
For counter1 = LBound(astrArray1) To UBound(astrArray1)
For counter2 = LBound(astrArray2) To UBound(astrArray2)
If astrArray1(counter1) <> astrArray2(counter2) Then
blnMP5 = False
ElseIf astrArray1(counter1) = astrArray2(counter2) Then
blnMP5 = True
End If
If blnMP5 = False Then
uniquesString = uniquesString & "," & astrArray2(counter2)
End If
Next counter2
Next counter1
findUniques = uniquesString
End Function
謝謝你的幫忙!即使一個數組長於另一個數組,它也可以工作嗎? – user2217895 2013-04-24 20:38:39
查看上面的答案。一個陣列比另一個大:) – 2013-04-24 20:39:56
謝謝!非常感謝您的幫助! – user2217895 2013-04-24 21:19:49