tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
The code below works to remove duplicates:
The question I have is why would I need to create NewArray?
I tried this but it returned nothing:
Thanks
Rich (BB code):
Option Explicit
Sub test()
Dim DIC As Scripting.Dictionary
Set DIC = New Scripting.Dictionary
Dim MyArray() As Variant
Columns(3).ClearContents
MyArray = Cells(1, 1).CurrentRegion.Value
Dim n As Long
For n = 1 To UBound(MyArray, 1)
DIC.Item(MyArray(n, 1)) = 0
Next n
MyArray = DIC.Keys
Dim NewArray() As Variant
ReDim NewArray(1 To DIC.Count, 1 To 1) As Variant
Dim a As Long
For a = 1 To DIC.Count
NewArray(a, 1) = MyArray(a - 1)
Next a
Cells(1, 3).Resize(DIC.Count, 1).Value = NewArray
Set DIC = Nothing
End Sub
The question I have is why would I need to create NewArray?
I tried this but it returned nothing:
Rich (BB code):
Option Explicit
Sub test2()
Dim DIC As Scripting.Dictionary
Set DIC = New Scripting.Dictionary
Dim MyArray() As Variant
Columns(3).ClearContents
MyArray = Cells(1, 1).CurrentRegion.Value
Dim n As Long
For n = 1 To UBound(MyArray, 1)
DIC.Item(MyArray(n, 1)) = 0
Next n
MyArray = DIC.Keys
'Neither this:
Cells(1, 3).Resize(DIC.Count, 1).Value = MyArray
' nor this works
Cells(1, 3).Resize(DIC.Count).Value = MyArray
Set DIC = Nothing
End Sub
Thanks