Recently I've found a very good script here on Stack Overflow. It works superbly, but I would like to adjust it a little bit - although my skill still doesn't let me to play with this kind of VBA very much. Until now, I've only failed in re-working this code.
My goal is to make this script do what it does, but from a fixed location - so I don't want to select it via a "question box" but copy a data range. For example: A1:A200
and paste it into another tab, like: DATA!A1:A200
Could you help me?
And the code:
Sub ListUniqueValues()
'lists the unique values found in a user-defined range into a
'user-defined columnar range
Dim SearchRng As Range
Dim ResultRng As Range
Dim Cel As Range
Dim iRow As Long
Set SearchRng = Application.InputBox("Select search range", _
"Find Unique Values", Type:=8)
Do
Set ResultRng = Application.InputBox("Select results columnar range", _
"Write Unique Values", Type:=8)
Loop Until ResultRng.Columns.Count = 1
iRow = 0
For Each Cel In SearchRng
If Application.WorksheetFunction.CountIf(ResultRng, Cel.Value) = 0 Then
'This value doesn't already exist
iRow = iRow + 1
If iRow > ResultRng.Rows.Count Then
MsgBox "Not enough rows in result range to write all unique values", _
vbwarning, "Run terminated"
Exit Sub
Else
ResultRng(iRow).Value = Cel.Value
End If
End If
Next Cel
'sort result range
'ResultRng.Sort ResultRng
End Sub