Excel conditional format: color cells

Posted on 2014-01-27
Last Modified: 2014-01-27

In Excel, I have a column which has four words which might occupy each cell: Internal, External, Unassigned, Unknown.

I would like to assign cell color, depending on which word was used in the cell...

Internal - blue (#3366FF)
External - orange (#FF6600)
Unassigned - gray (#969696)
Unknown - red (#FF0000)

Can you help me get started on how to specify these in VBA?

Thank you!
Question by:johndarby
  • 3
  • 2
LVL 11

Assisted Solution

Angelp1ay earned 250 total points
ID: 39813415
I suggest you use standard conditional formatting instead of VBA.

Select column, apply conditional formattingEnter the text to match, select custom formattingSelect fill, more colorsLook up the RGB equivalents of your HEXEnter the RGB value

Accepted Solution

dustock earned 250 total points
ID: 39813416
This should help you along the way, put it in the sheet code for what ever sheet you are using.  Be sure to change Sheets(1) to what ever number you are using and change the Column from A in line 3 and line 5 to what ever column you are using.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim strText As String
    LastRow = Sheets(1).Range("A65536").End(xlUp).Row

    If Intersect(Target, Me.Range("A2:A" & LastRow)) Is Nothing Then
        Exit Sub
        'Converting the text to lower case to compare
        strText = LCase(Target.Value)
        Select Case strText
            Case "internal"
                Target.Interior.ColorIndex = 5 'Blue
            Case "external"
                Target.Interior.ColorIndex = 46 'Orange
            Case "unassigned "
                Target.Interior.ColorIndex = 16 'Gray
            Case "unknown"
                Target.Interior.ColorIndex = 3 'Red
            Case Else
        End Select
    End If
End Sub

Open in new window

LVL 11

Expert Comment

ID: 39813418
Here is an example Excel and a website that does HEX-RGB conversion:
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Expert Comment

ID: 39813427
Forgot to mention on my post you can use sheet name vs sheet index.  Just put name inside quotes Sheets(1) same as Sheets("Sheet1")
LVL 11

Expert Comment

ID: 39813429
Here are your RGB values:
51   102  255 - Internal
255  102    0 - External
150  150  150 - Unassigned
255    0    0 - Unknown

Open in new window


Author Closing Comment

ID: 39813492
Thank you, both! Very helpful to get a peek at 2 options!

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now