• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

VBA xlColumnClustered Only 1 color|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / VBA xlColumnClustered Only 1 color|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosVBA xlColumnClustered Only 1 color
sp_PrintTopic sp_TopicIcon
VBA xlColumnClustered Only 1 color
Avatar
Steven Behr
Member
Members

Power Query
Level 0
Forum Posts: 85
Member Since:
January 30, 2020
sp_UserOfflineSmall Offline
1
February 21, 2020 - 10:04 am
sp_Permalink sp_Print

Hi,

 

I have created a VBA Charting system with Pie charts, Lines, Scatter and columns.

All charts except for the column chart has only 1 colour (Blue). I would prefer different colours for different series 

 

Can anyone verify if there is a code for the standard series colours

The code is below and the data block

If ComboBox1.Text = "Select a Chart" Then
MsgBox "Select a Chart from the dropdown List"
Exit Sub
End If
Dim MyChart2 As Chart
Dim ChartData2 As Range
Dim ChartIndex2 As Integer
Dim ChartName2 As String
ChartIndex2 = ComboBox1.ListIndex
Select Case ChartIndex2
Case 0
Set ChartData2 = Sheet3.Range("B41:B45") ' A2:A7
ChartName2 = Sheet3.Range("A40") ' Correct
End Select
Application.ScreenUpdating = False
Set MyChart2 = Sheet3.Shapes.AddChart(xlColumnClustered).Chart
 
MyChart2.SeriesCollection.NewSeries
MyChart2.SeriesCollection(1).Name = ChartName2
MyChart2.SeriesCollection(1).Values = ChartData2
MyChart2.SeriesCollection(1).XValues = Sheet3.Range("A41:A45")
MyChart2.FullSeriesCollection(1).ApplyDataLabels
Dim imageName3 As String
imageName3 = Application.DefaultFilePath & Application.PathSeparator & "TempChart.gif"
MyChart2.Export Filename:=imageName3
ActiveSheet.ChartObjects(1).Delete
Application.ScreenUpdating = True
ReportCreator.Image3.Picture = LoadPicture(imageName)
 
Data Block is below
Incident Severity Severity
Low 3
Medium 1
High 1
Extreme 1
Not Rated 12
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
February 21, 2020 - 12:49 pm
sp_Permalink sp_Print sp_EditHistory

Hi Steve,

You can set the series colours like this

Sub ChangeSeriesColours()

ActiveSheet.ChartObjects("Chart 1").Activate

With ActiveChart

.SeriesCollection(1).Interior.Color = RGB(255, 0, 0) 'Red
.SeriesCollection(2).Interior.Color = RGB(0, 255, 0) ' Green

End With

End Sub

See attached.

Regards

Phil

Avatar
Steven Behr
Member
Members

Power Query
Level 0
Forum Posts: 85
Member Since:
January 30, 2020
sp_UserOfflineSmall Offline
3
February 21, 2020 - 1:53 pm
sp_Permalink sp_Print

Thanks Phil,

 

This works well, however, with a pie chart all the series "Low, Medium, High ect are in different colors which is good.

 

But what you have set is changed the color to red as an example. Why cant I have, like the pie chart automatically have those different colors for individual series???

Steve

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
February 21, 2020 - 2:30 pm
sp_Permalink sp_Print

Hi Steve,

As always, illustrating what you are talking about saves me a lot of time figuring it out.  Please provide a workbook.

I'm not entirely sure what you are referring to.  If you have 2 series that you want to plot on a bar chart, then they will be in different colours.

If what you are talking about is that you are trying to plot 2 series on a scatter chart, against a 3rd series of values on the y-axis, then if you do this using Insert->Recommended Chart, Excel is probably disregarding the 3rd series and plotting Series 1 against Series 2.  Hence you end up with only 1 colour for your points.

In such a case a scatter isn't the best chart.

Regards

Phil

Avatar
Steven Behr
Member
Members

Power Query
Level 0
Forum Posts: 85
Member Since:
January 30, 2020
sp_UserOfflineSmall Offline
5
February 21, 2020 - 2:56 pm
sp_Permalink sp_Print

Hi Phil,

ALT F11 - Report Creator

Select ComboBox1 "Select A Chart"...Load Chart.

Image 3 & 4 show column chart which are blue "Incident Severity" & "Hazard type".

The pie charts 1,2 & 5 are in their proper colors so I dont need any mods for that.

Thanks

 

Steve

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
February 22, 2020 - 1:37 pm
sp_Permalink sp_Print

Hi Steve, 

the columns in the column chart are all the same colour because they are not touching each other.  There's no need to make them different colours as there is space between the columns.

The pie chart segments are different colours because this is necessary to indicate each segment - they are all touching.

You should use colour to highlight something on a chart.  Making all the columns different colours can make it look very busy and hard on the eye.  But if you really want to you can use this

 

Sub ColourPoints()

Dim MyChart2 As Chart
Dim i As Long

ActiveSheet.ChartObjects("Chart 9").Activate

For i = 1 To ActiveChart.FullSeriesCollection(1).Points.Count

ActiveChart.FullSeriesCollection(1).Points(i).Select

With Selection.Format.Fill

.ForeColor.RGB = RGB(Rnd() * 100, Rnd() * 100, 155)

End With

Next i

End Sub

 

We don't recommend pie charts anyway in most cases, they just aren't good for representing data.

https://www.myonlinetraininghu.....ie-chart 

Regards

Phil

Avatar
Steven Behr
Member
Members

Power Query
Level 0
Forum Posts: 85
Member Since:
January 30, 2020
sp_UserOfflineSmall Offline
7
February 24, 2020 - 6:42 am
sp_Permalink sp_Print

Thanks Phill,

 

That works very well.

 

I understand the basis of colours of charts however my OH&S manager wanted the status Quo! - Just to keep him haoy.

But thanks for that you did well

 

Steve

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
stuart burge
Bruce Tang Nian
Scot C
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Forum Stats:
Groups: 3
Forums: 24
Topics: 6223
Posts: 27295

 

Member Stats:
Guest Posters: 49
Members: 31920
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.