+ Reply to Thread
Results 1 to 2 of 2

Color chart caption with VBA

  1. #1
    Registered User
    Join Date
    09-09-2017
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    1

    Color chart caption with VBA

    Guys.

    I need some help to create a macro that chooses the color of the graph. I have several graphs that I will use here as an example, name of employees. In some graphics can have Fernando, Fábio, etc, others can have only Fernando. Not all employees are present on all graphics.

    I need that in all the graphs the "Fernando" is of the red color and the "Fábio" in all the graphs that it appears is of the color blue.

    Here is the code I already have, but it isn't working.

    Sub macro_grafico()
    If ActiveSheet.ChartObjects("Gráfico 20").Activate Then
    ActiveChart.SeriesCollection("Fernando").Select
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 255, 0)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Fabio").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 235, 158)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Priscilla").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(204, 51, 0)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Bruna").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(49, 133, 156)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Bárbara").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(102, 0, 102)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Julio").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(195, 214, 155)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Henrique").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(204, 193, 218)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Cassiano").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(55, 96, 146)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Leandro").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(64, 49, 82)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Jorge").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(33, 89, 104)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Guilherme").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(127, 127, 127)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Lucas").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(119, 147, 60)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Pedro").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(1, 13, 255)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Sergio").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(152, 72, 7)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Gustavo").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(155, 187, 89)
    .Transparency = 0
    .Solid
    End With
    ElseIf ActiveChart.SeriesCollection("Daniele").Select Then
    With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(0, 0, 0)
    .Transparency = 0
    .Solid
    End With
    End If
    End Sub
    I really appreciate your help.

    Tks

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Color chart caption with VBA

    Bom día, welcome to the forum.
    I imagine you already have a tab;e with these person's names. I would suggest that you add a column and place the color value you want in that column
    You determine a color value for each name and you could even give this cell the name of this person
    All you need to do is refer to the cell based upon the selected SeriesCollection's name
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Change Chart TextBox 1 caption via macro
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-18-2014, 09:33 AM
  2. [SOLVED] Change label caption's font color based on value in another textbox
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-19-2013, 01:59 PM
  3. [SOLVED] Is it possible to do a comm.button with scrolling caption /changing caption?
    By Lkivagten in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2012, 08:10 AM
  4. Return the Name/Caption and Color of a Command Button
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2007, 10:52 AM
  5. Color of custom button caption
    By shashi1515 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2006, 12:10 PM
  6. Excel should let me caption individual bars in a stacked chart
    By Matt Turnbull in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-14-2006, 10:00 PM
  7. [SOLVED] shapes caption on chart
    By nk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-29-2005, 12:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1