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
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
53 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
1 Comment
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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 demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

808 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