Looking up color table

In Playing around with colors in VBA I introduced the concept of a color table. This is just a list of a name and a matching hex color code in a big excel table. I have been creating a large number of color schemes in the cDataSet.xlsm workbook, and each color is keyed on a color scheme name and a color name. We’ve filled in the other columns using the functions mentioned in Playing around with colors in VBA but only the name and hex value are of interest. Here’s the start of the table showing some pantone colors



Making Swatches


We’ll start with a simple example of using that table to create a color swatch, given a list of color names. This time we are going to choose colors from the dulux color scheme. They look like this in the color table.
I’m just using these because they happen to be together – you can of course use any list or number of colors in the color table.
We’re aiming to create this swatch
And using the libraries in the cDataSet.xlsm workbook, here’s the code
Public Sub makeSimpleSwatches()
    Dim r As Range, nameList As Variant, i As Long, self As cDataSet
    ' going to make some color swatches
    Set r = firstCell(wholeSheet("swatches"))

    ' going to use some dulux names
    Const schemePrefix = "dulux-"
    ' get the color map table
    With getcolorMap()
        ' refer to the dataset for later
        Set self = .self
        ' these are our colors
        nameList = Array( _
            "charred chocolate", _
            "charred clay", _
            "cheater", _
            "cheesy grin", _
            "chenille" _
        ' look up the colors, get and good text colors
        For i = LBound(nameList) To UBound(nameList)
            With r.Offset(, i - LBound(nameList))
                .Interior.color = self.value(schemePrefix & nameList(i), "rgb")
                .Font.color = makeColorProps(.Interior.color).textColor
                .value = nameList(i)
            End With
        Next i

    End With
End Sub

See more about color topics here