Excel VBA

css navigation by Css3Menu.com

Color Numbers

This is a 2 for the price of one example.

I was recently working on a large program that created many worksheets. I decided that the tabs needed to be color coded by function. The colors I worked with were not coming out the way I envisioned, so I needed to discover the true Excel code for the colors I wanted..

Sub Colors()
    Dim I As Long
    Sheets.Add
    Cells(1, 1) = "Color Sample"
    Cells(1, 2) = "Color Index"
    Cells(1, 3) = "Interior Color"
    For I = 1 To 56
        Cells(I + 1, 1).Interior.ColorIndex = I
        Cells(I + 1, 2).Value = I
        Cells(I + 1, 3).Value = Cells(I + 1, 1).Interior.Color
    Next I
    Columns.AutoFit
End Sub

 

 

Sub ReadColor()
    Dim C       As Long
    Dim Colr    As Variant
    Dim R       As Long
    C = ActiveCell.Row
    R = ActiveCell.Column
    Colr = Cells(C, R).Interior.Color
    MsgBox Colr & " displayed at " & vbCrLf & "Cell row " & C & " column " & R
    Debug.Print Colr & " number"
End Sub

I guess I am a little obsessed with color. Before I was in IT, I studied Commercial Design.

© 2017-2018

Updated:  11/20/2018 20:24
This page added:  19 September 2017