?
Solved

Would like to assign RGB colors for fill, text and border based on text values for a range of values using VBA

Posted on 2016-07-25
1
Medium Priority
?
60 Views
Last Modified: 2016-07-29
I was given code a few years back to conditionally color a range of values based on text (e.g. book to price), but I need to expand beyond the icolor 57 limit limitation.  Any insights would be greatly appreciated.  Attached is the code that works using icolor.  Thank you.

' Revised worksheet code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Not Intersect(Target, Range("c241:k277")) Is Nothing Then
        ColourCells Intersect(Target, Range("c241:k1277"))
    End If
 
End Sub
 
' NEW MODULE
 
Sub ColourThemAll3()
    ColourCells ActiveSheet.Range("c134:k152")
End Sub
Sub ColourCells(rngIn As Range)
    Dim rngcell As Range
    Dim iColor As Long
    For Each rngcell In rngIn
        With rngcell
            Select Case .Value
     
                Case "Book Value per Share to Price", "Cashflow per Share to Price", "Dividend Yield", "Earnings per Share to Price", "EBITDA to EV", "EBITDA to Price", "IBES Dividend Yield", "IBES Earnings Yield", "IBES Sales Yield", "Sales per Share to Price", "Sales to EV", "Free Cashflow Yield"
         
                    iColor = 5
                    .Font.Color = RGB(255, 255, 255)
                     
                Case "Growth in Earnings per Share", "IBES 12 Month Forward  Growth in Earnings per Share", "IBES Earnings Long Term Growth", "IBES FY1  Earnings Revisions 1M Sample", "IBES FY1  Earnings Revisions 3M Sample", "IBES FY2  Earnings Revisions 1M Sample", "IBES FY2  Earnings Revisions 3M Sample", "IBES Sales 12 Mth Growth", "IBES Sales Long Term Growth", "Income to Sales", "Return on Equity", "Sales Growth", "Sustainable Growth Rate"
         
                    iColor = 10
                    .Font.Color = RGB(255, 255, 255)
                   
                Case "Beta", "Market Cap (Large Cap)*"
         
                    iColor = 3
                    .Font.Color = RGB(255, 255, 255)
                     
                Case "Momentum 12 Mth", "Momentum 6 Mth", "Momentum Short Term (6 Month Exp Wtd)"
         
                    iColor = 1
                    .Font.Color = RGB(255, 255, 255)
                     
                Case "Debt to Equity", "Foreign Sales as a % Total Sales"
         
                    iColor = 36
                    .Font.Color = RGB(0, 0, 0)
                     
                Case "Low Gearing", "Stability Of Earnings Growth", "Stability Of FY1 Revisions", "Stability Of IBES 12 Mth Growth Forecast", "Stability of Returns", "Stability Of Sales Growth"
         
                    iColor = 18
                    .Font.Color = RGB(255, 255, 255)
                Case Else
         
                    'Whatever
         
            End Select
         
             
         
            .Interior.ColorIndex = iColor
        End With
    Next rngcell
 
End Sub
0
Comment
Question by:majervis
[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
1 Comment
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 41728534
You should be able to set .Interior.Color to a RGB value like you do with the font.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
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.

770 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