IREALLYambatman
Board Regular
- Joined
- Aug 31, 2016
- Messages
- 63
My Idea: Hey Guys, so I have a Row of data, with a bunch of Sample ID's in them. I add all those values from a row into an array, then only keep the unique ones. Now I want VBA to search the array for the values in the array, if there's a match, then deletes the value from the array and also does other stuff. Since it deletes the value from the Array then the second time that value occurs, the value will not be found in the unique array.
Example Data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]A
[/TD]
[TD]C
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]First Occurance, delete "A" from unique array, and also do stuff
[/TD]
[TD]First Occurance, delete "A" from unique array, and also do stuff
[/TD]
[TD] Value shouldn't be found in unique array, so not first occurance, do nothing.
[/TD]
[/TR]
</tbody>[/TABLE]
My (mostly from forums) code:
Example Data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]A
[/TD]
[TD]C
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]First Occurance, delete "A" from unique array, and also do stuff
[/TD]
[TD]First Occurance, delete "A" from unique array, and also do stuff
[/TD]
[TD] Value shouldn't be found in unique array, so not first occurance, do nothing.
[/TD]
[/TR]
</tbody>[/TABLE]
My (mostly from forums) code:
Code:
Dim ArrayOfSampleIDs() As Variant
Dim UniqueArrayOfSampleIDs() As Variant
Dim i As Long
ReDim ArrayOfSampleIDs(3 To LastCol)
For i = 3 To LastCol
ArrayOfSampleIDs(i) = Cells(11, i).value ' Array Of ALL sample ID's
Next
UniqueArrayOfSampleIDs = RemoveDupes(ArrayOfSampleIDs) ' Array Of UNIQUE sample ID's
For i = 3 To LastCol
IsInArray = (UBound(Filter(UniqueArrayOfSampleIDs, Cells(11, i).value)) > -1)
If IsInArray Then
'Delete This Value From Array(UniqueArrayOfSampleIDs, Cells(11, i).value) [U][I][B] <------- Need Help Here (this is obviously not a real function)[/B][/I][/U]
'Do Otherstuff (this is ready to go)
End If
Next i
Function RemoveDupes(InputArray As Variant) As Variant
Dim X As Long
With CreateObject("Scripting.Dictionary")
For X = LBound(InputArray) To UBound(InputArray)
If Not IsMissing(InputArray(X)) Then .Item(InputArray(X)) = 1
Next
RemoveDupes = .Keys
End With
End Function