function to return unique values to activecell

john316swan

Board Regular
Joined
Oct 13, 2016
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Good Morning from California,

I am trying to turn a subroutine that I have borrowed from @hiker95 into a function but I cannot get the output the dictionary to the activecell. I have tried a number of ways, but I just can't figure it out. I have verified that all of the values are being stored in the dictionary, but can't seem to output them to the activecell. Thank you in advance, here is the code:

VBA Code:
Function Unique(Duplicated As Range)
Dim d As Object, c As Variant, dup As Long, output As Range

Set output = ActiveCell
Set d = CreateObject("Scripting.Dictionary")
c = Duplicated

For dup = 1 To UBound(c, 1)
    d(c(dup, 1)) = 1
Next dup

'Dim key As Variant
'    For Each key In d.keys
'        Debug.Print key, d(key)
'Next key

Range(output).Resize(d.Count) = Application.Transpose(d.keys)

End Function
 
Glad we could help & thanks for the feedback
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,821
Messages
6,121,755
Members
449,049
Latest member
excelknuckles

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