There's actually some way of doing this in Excel, but
before I found that (and I don't recall what it is
anymore), I wrote a little program to do what you are
asking. It's not the most elegant piece of code, but
it works.
I actually have a whole series of these that I can
call upon through a form that will do any of the
following operations:
Add/subtract/multiply/divide all number cells in
selected range by X.
Trim leading/trailing spaces in text cells in selected range.
Proper case all text cells in selected range.
Generate a list of all unique entries in selected range.
Here's the code bit that does the unique list:
Usage: select the cells in one column that have the
data you wish to draw a unique list from. Then run
the UniqueList macro, which creates an alphabetized
list of all the unique cells in a new workbook.
Sub UniqueList()
Application.ScreenUpdating = False
Dim ThisBook, DataBook, sR As Integer, sC As Integer, R As Integer
Set ThisBook = ActiveWorkbook
sR = Selection.Row
sC = Selection.Column
Workbooks.Add
Set DataBook = ActiveSheet
ThisBook.Activate
R = 1
On Error GoTo Finish
Do
DataBook.Cells(R, 1).Value = ActiveCell.Value
Selection.ColumnDifferences(ActiveCell).Select
R = R + 1
Loop
Finish:
Cells(sR, sC).Select
DataBook.Activate
Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Columns("A:A").AutoFit
Range("A1").Select
Application.ScreenUpdating = True
End Sub
Hope this helps.
Mike