distinct from array dump, VBA question

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
I have this code:

.Range("A2:A" & UBound(mylog) + 1) = WorksheetFunction.Transpose(mylog)

It at the end of the Sub, it dumps all the list values from the array starting at
A2 to the last row of my Control workbook. This works, but because of the complexity of my code due to business rules, I have duplicates at the end, which I filter out by selecting it column and using AutoFilter with distinct.

Is there a way to do this step in VBA, to alter that one liner of code, so that it dumps
the distinct values already out of the array, would save me one step, thank you!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
do you guys think this would work ? is there a better way ?

Set d = CreateObject("Scripting.Dictionary")

Dim i As Long
For i = LBound(mylog) To UBound(mylog) ' make it distinct
d(mylog(i)) = 1
Next i
.Range("A2:A" & UBound(mylog) + 1) = WorksheetFunction.Transpose(mylog) 'dump it into the sheet
 
Upvote 0
I solved this using a google search and custom adjustment for my needs, posting incase someone finds it useful...

Set d = CreateObject("Scripting.Dictionary")

Dim ii As Long
For ii = LBound(mylog) To UBound(mylog) ' make it distinct
d(mylog(ii)) = 1
Next ii

Dim v As Variant
For Each v In d.Keys()

vv = 2
.Range("A" & vv).Value = v
vv = vv + 1

Next v


Its not perfect, but it works well :- ) thanks!
 
Upvote 0
there, the vv = 2 was in the wrong place, it would re-set to 2 within each loop, darn it...

Set d = CreateObject("Scripting.Dictionary")

Dim ii As Long
For ii = LBound(mylog) To UBound(mylog) ' make it distinct
d(mylog(ii)) = 1
Next ii

Dim v As Variant
vv = 2
For Each v In d.Keys()

.Range("A" & vv).Value = v
vv = vv + 1

Next v
 
Upvote 0
In your first post, you said
I have duplicates at the end
If that's the only place you have duplicates, and you know how many unique value there are, why not just write out only the top part of the array?

What kind of data is in the array?
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,572
Members
452,927
Latest member
whitfieldcraig

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