By "distinct list" I am assuming you meant a list of UNIQUE values contained
in column A - i.e. I am assuming there are more colours than just blue and
brown and you want to obtain a list of only unique colours.
I suggest using a Dynamic Named Range for the entries in column A. If you
are not familiar, the definition of this named range automatically adusts to
the number of entries. These are particularly usefull for charting.
***********************************
To create the Dynamic Named Range:
1. Open the Define Name dialog: Insert > Name > Define
2. In the "Names in workbook:" window enter: ColourListRng
3. In the "Refers to:" window enter:
=OFFSET(Sheet1!$A$1, 0, 0, COUNTA(Sheet1!$A:$A), 1)
The above formula assumes that the name of the worksheet is "Sheet1" and the
colour list starts at cell A1. Change to suit. The formula will require
adjustment if there are more data in column A below the colour list.
4. Click the Add button.
5. Close the dialog.
******************************
Macro to extract unique values from the colour list in column A
(ColourListRng). These extracted values will be copied to column B:
Sub GetUniques()
Dim r As Range, r2 As Range
Dim c As Range, cc As Range
Dim ws As Worksheet
Set r = Range("ColourListRng")
Set ws = r.Parent
Set c = r(1)
Set cc = r(1, 2)
For Each c In r
Set r2 = ws.Range(r(1), c)
If Application.CountIf(r2, c) = 1 Then
cc = c
Set cc = cc(2)
End If
Next
End Sub
********************************
Required change to formula that counts instances of each colour:
In place of the formula I gave you earlier:
=CountIf($A$1:$A$100, B1)
Substitute:
=CountIf(ColourListRng, B1)
Drag this formula down as instructed earlier.
********************************
How to test accuracy of ColourListRng:
1. Open the Define Names dialog again and click inside the "Refers to:"
window. The entries in the list and only these cells should be highlighted
with dashed lines.
2. Change the number of entries in the list and retest to ensure it adjusts
correctly. Post if it does not.
Regards,
Greg