Storing variables into array after removing duplicates

Lavina

Board Regular
Joined
Dec 18, 2018
Messages
75
Hello guys,

i'm storing a range of variables into a 1d array and i want to remove the duplicate variables beforehand instead of clearing the array after.

My function is:
Code:
Function StoringIntoArray(startSKU As Long, endSKU As Long, columnSKU As Long)
    Dim arTmp
    Dim skuArray()
    Dim counter As Long, i As Long
    Range(Cells(startSKU, columnSKU), Cells(endSKU, columnSKU)).RemoveDuplicates Columns:=Array(1), Header:=xlNo
    counter = UBound(arTmp, 1)
    ReDim skuArray(1 To counter)
    For i = 1 To counter
        skuArray(i) = arTmp(i, 1)
    Next i
    Erase arTmp
    StoringIntoArray = skuArray()
End Function

Currently it doesn't run because arTmp is empty.
My idea was to make:
Code:
arTmp = Range(Cells(startSKU, columnSKU), Cells(endSKU, columnSKU)).RemoveDuplicates Columns:=Array(1), Header:=xlNo
but that doesn't work. And i don't really want to remeasure my range selection after duplicates have been removed, nor do i want to add empty cells into array, what would be the best way to proceed?

I can of course make my own remove duplicates function, but i can just run that on the array later
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about
Code:
Function StoringIntoArray(startSKU As Long, endSKU As Long, columnSKU As Long)
    Dim Cl As Range
    
    With CreateObject("scripting.dictionary")
      For Each Cl In Range(Cells(startSKU, columnSKU), Cells(endSKU, columnSKU))
         .Item(Cl.Value) = Empty
      Next Cl
      StoringIntoArray = .Keys
   End With
End Function
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top