Sub display_colours()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long
Dim str0 As String, str As String
Dim x As Integer
On Error GoTo Finalise
'titles
Cells(1, 1).Value = "Color"
Cells(1, 2).Value = "HEX"
Cells(1, 3).Value = "Red"
Cells(1, 4).Value = "Green"
Cells(1, 5).Value = "Blue"
Cells(1, 6).Value = "RGB"
Cells(1, 1).EntireRow.Font.Bold = True
For i = 1 To 56
Cells(i + 1, 1).Interior.ColorIndex = i
Cells(i + 1, 1).Value = "[Color " & i & "]"
Select Case Cells(i + 1, 1).Interior.ColorIndex
Case 1, 3, 5, 9, 10, 11, 12, 13, 14, 16, 18, 21, 23, 25, 29, 30, _
31, 32, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
Cells(i + 1, 1).Font.ColorIndex = 2
Case Else
Cells(i + 1, 1).Font.ColorIndex = 1
End Select
str0 = Right("000000" & Hex(Cells(i + 1, 1).Interior.Color), 6)
Cells(i + 1, 2) = "#" & str0
Cells(i + 1, 3).Formula = "=Hex2dec(""" & Right(str0, 2) & """)"
Cells(i + 1, 4).Formula = "=Hex2dec(""" & Mid(str0, 3, 2) & """)"
Cells(i + 1, 5).Formula = "=Hex2dec(""" & Left(str0, 2) & """)"
Cells(i + 1, 6).Value = "RGB(" & Cells(i + 1, 3) & "," & Cells(i + 1, 4) & "," & Cells(i + 1, 5) & ")"
Next i
'autofit the columns
For x = 1 To ActiveSheet.UsedRange.Columns.Count
Columns(x).EntireColumn.AutoFit
Next x
Finalise:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub