Avatar of majervis
majervis
Flag for United States of America asked on

VBA to set fill color on Excel Charts

I have some code that someone helped me with
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 = 6
                    .Font.Color = RGB(0, 0, 0)
                     
                Case "Low Gearing", "Low Accruals", "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

Open in new window

awhile ago.  I need to be able to use the RGB colors instead of what I am currently using for fill colors on excel bar charts.
Microsoft ApplicationsOffice Productivity

Avatar of undefined
Last Comment
Rgonzo1971

8/22/2022 - Mon
Rgonzo1971

majervis

ASKER
Thank you.  Is it not possible to use the RGB way of creating colors.  I don't have any knowledge about this.  Just curious.
Rgonzo1971

It depends on which Version of Excel you have
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
majervis

ASKER
2010
ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.