Excel Workbook | ||||||
---|---|---|---|---|---|---|
B | C | D | E | |||
4 | List | * | Sorted | Yahya result, not sorted | ||
5 | Apple | * | Apple | Apple | ||
6 | Mango | * | Cucumber | Mango | ||
7 | Mango | * | Grapes | Pineapple | ||
8 | Pineapple | * | Mango | Grapes | ||
9 | Apple | * | Pineapple | Cucumber | ||
10 | Grapes | * | * | * | ||
11 | Cucumber | * | * | * | ||
12 | Pineapple | * | * | * | ||
13 | Mango | * | * | * | ||
Sheet1 |
Hi GTO,
Yes J is oversized then J is resized by count uniques which is contained in n.
Biz
Thank you Biz
I do not believe I knew (or I had most certainly forgotten) that you could plop a bigger array into a smaller range and the excess would just drop out.
Thanks again,
Mark
Hi Mark,
I am still learning. Do you think i should redim array?
Biz
Sub exa()
Dim Vals, Val1
Vals = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Value
If IsArray(Vals) Then
With CreateObject("Scripting.Dictionary")
For Each Val1 In Vals
If Not IsEmpty(Val1) Then .Item(Val1) = Empty
Next
Range("J1").Resize(Rows.Count).ClearContents
Range("J1").Resize(UBound(.Keys) + 1).Value = Application.Transpose(.Keys)
End With
End If
End Sub
Hi Biz,
No. I was being sincere in stating that I didn't realize or had forgotten. I see no harm in letting the array 'over-run' harmlessly. Also, since it would be the first dimension that would need reduced, this is not possible (I am presuming you meant Redim Preserve), as only the last dimension can be resized and retain the values in the array.
I had come up with:
...which was a few lines shorter and I initially was wondering about any advantage to the "extra" steps yours uses in IF .Exists and building the array. After thinking about it, (and FWIW from a fellow "still learning plenty") if I was going to only do it one way, I would use yours, since worrying about memory limitations (for a 'weaker' laptop for instance) with .Transpose is no worry at all. NiceRich (BB code):Sub exa() Dim Vals, Val1 Vals = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp)).Value If IsArray(Vals) Then With CreateObject("Scripting.Dictionary") For Each Val1 In Vals If Not IsEmpty(Val1) Then .Item(Val1) = Empty Next Range("J1").Resize(Rows.Count).ClearContents Range("J1").Resize(UBound(.Keys) + 1).Value = Application.Transpose(.Keys) End With End If End Sub