• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Assigning Bar Charts Different Colors with VBA Macro

waller99

New Member
I have some excel sheets that are formatted like the following:


COMPANY | TOTAL | RGB
company1 | 10 | 255,000,000
company2 | 20 | 000,255,000
company3 | 30 | 000,000,255
...
and so on...


My question is that I would like to have a macro that runs on this basic file and creates a bar graph with the data. Then it utilizes the RGB values in the column to change the specific bar for that row. Is this possible, and if so, can someone point me in the right direction? I know a little VBA but I can't figure out how to do this. Also there isn't a preset number of rows in the files.

Thanks in advance..

Dustin
 
I was assisted on another forum with this basic code.
Code:
Sub Macro1()
  ActiveSheet.Shapes.AddChart.Select
  ActiveChart.SeriesCollection(1).Points(1).Select
  With Selection.Format.Fill
  .Visible = msoTrue
  .ForeColor.RGB = RGB(255, 0, 0)
  .Transparency = 0
  .Solid
  End With
  ActiveChart.SeriesCollection(1).Points(2).Select
  With Selection.Format.Fill
  .Visible = msoTrue
  .ForeColor.RGB = RGB(0, 255, 0)
  .Transparency = 0
  .Solid
  End With
  ActiveChart.SeriesCollection(1).Points(3).Select
  With Selection.Format.Fill
  .Visible = msoTrue
  .ForeColor.RGB = RGB(0, 0, 255)
  .Transparency = 0
  .Solid
  End With
End Sub

What I need is the RGB values in this code to use the values in the sheet under column c. Plus this is static for the 3 rows of data. I need it to work on unlimited rows coloring each bar the corresponding color in column C.
 
Back
Top