Hi all,
I have thought and array'd myself into a corner and would love a guiding light on this one...
I have 2 arrays and want to populate a third with the values that match between Array1 and Array2.(up to this point everythign works)
And (this is where I am stumbling) I want to populate Array4 with all matching values and all unique values, but no duplicates from Array1 and Array2.
I am working in a test file and not yet working with my actual data. (I want to make it work small scale first) I cannot find a way search through Array2, find an element that does not match any in Array1 and load to Array4. I've tried Join, Match, strange loops
(values need to be a mixture of string and integer)
Thanks for any advice....BMRC
Worksheets "TEST" has the following:
I have thought and array'd myself into a corner and would love a guiding light on this one...
I have 2 arrays and want to populate a third with the values that match between Array1 and Array2.(up to this point everythign works)
And (this is where I am stumbling) I want to populate Array4 with all matching values and all unique values, but no duplicates from Array1 and Array2.
I am working in a test file and not yet working with my actual data. (I want to make it work small scale first) I cannot find a way search through Array2, find an element that does not match any in Array1 and load to Array4. I've tried Join, Match, strange loops
(values need to be a mixture of string and integer)
Thanks for any advice....BMRC
Worksheets "TEST" has the following:
Code:
Sub Test()
'Build Array 1
LastRowA1 = Application.WorksheetFunction.CountA(Worksheets("TEST").Range("A:A")) - 1
LastColumnA1 = 2
ColNum1 = LastColumnA1
RowNum1 = LastRowA1
ReDim Array1(ColNum1, RowNum1)
For x = 0 To ColNum1 - 1
For i = 0 To RowNum1
Array1(x, i) = Worksheets("TEST").Cells(i + 1, x + 1).Value
Next
Next
'Build Array 2
LastRowA2 = Application.WorksheetFunction.CountA(Worksheets("TEST").Range("C:C")) - 1
LastColumnA2 = 2
ColNum2 = LastColumnA2
RowNum2 = LastRowA2
ReDim array2(ColNum2, RowNum2)
For x = 0 To ColNum2 - 1
For i = 0 To RowNum2
array2(x, i) = Worksheets("TEST").Cells(i + 1, x + 3).Value
Next
Next
'Build Array 3
'Shows only matches between Array1 and Array2
ColNum = 2
RowNum = RowNum1 + RowNum2
ReDim Array3(ColNum, RowNum)
Array3(0, 0) = "Matching only"
For i = 1 To RowNum1
For ii = 1 To RowNum2
If Array1(0, i) = array2(0, ii) Then
Array3(0, i) = Array1(0, i)
Array3(1, i) = Array1(1, i)
End If
Next ii
Next i
'Build Array4
'TEST (Want to buid array that has All of Array1 and the unique values from Array2)
ColNum = 2
RowNum = RowNum1 + RowNum2
ReDim Array4(ColNum, RowNum)
Array4(0, 0) = "Combined Array"
For x = 0 To ColNum
For i = 1 To RowNum1
Array4(x, i) = Array1(x, i)
Next
Next
For x = 0 To RowNum
If Array4(0, x) = "" Then
EndArray = x
x = RowNum
End If
Next x
''This works, but only if the lists are identical and in order except for the new values.(not a true search)
For i = 1 To RowNum2
For x = 0 To RowNum
If Array4(0, x) = "" Then
EndArray = x
x = RowNum
End If
Next x
If array2(0, i) <> Array4(0, i) Then
Array4(0, EndArray) = array2(0, i)
Array4(1, EndArray) = array2(1, i)
End If
Next i
End Sub