Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel conditional format: color cells

Posted on 2014-01-27
6
Medium Priority
?
595 Views
Last Modified: 2014-01-27
Greetings,

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!
JohnD
0
Comment
Question by:johndarby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 11

Assisted Solution

by:Angelp1ay
Angelp1ay earned 1000 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
0
 
LVL 9

Accepted Solution

by:
dustock earned 1000 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
    Else
        '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

0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39813418
Here is an example Excel and a website that does HEX-RGB conversion:
http://www.javascripter.net/faq/hextorgb.htm
Example.xlsx
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 9

Expert Comment

by:dustock
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")
0
 
LVL 11

Expert Comment

by:Angelp1ay
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

0
 
LVL 1

Author Closing Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

721 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