Thank you for the reference. It looks like a great resource. However, I am trying to create an array within a function that I can utilize in other section of the function. Any suggestions?
Chris
Try the following. It assumes that the selection is a single range in one column and the selection has already been sorted.
Sub UniqueItems()
Dim array1 As Variant
Dim array2
Dim J As Long, K As Long
array1 = Application.Transpose(Selection)
J = 0
For K = LBound(array1) To UBound(array1)
If J = 0 Then
J = 1
ReDim array2(1 To 1)
array2(K) = array1(K)
Else
If array1(K) <> array1(K - 1) Then
J = J + 1
ReDim Preserve array2(1 To J)
array2(J) = array1(K)
End If
End If
Next
End Sub
Celia
Perfect!!! Thank you ever so much for your help. Additionally, as a novice programmer, one item that is uncertain to me is why you have re-dimension the lower and upper bounds for array2(i.e., ReDim array2(1 to j) vs just the upper bound. Any explanation would be greatly appreciated. Again, thank you for support.
Chris
I always ReDim the lower and upper bounds as a matter of habit, but a ReDim of only the upper bound achieves the same thing (I think).
Celia
Chris
Have a look at :-
http://www.cpearson.com/excel/duplicat.htm#ExtractingUnique
There is worksheet formula at this site for extracting unique entries. Perhaps you can use this to do what you want?
Celia