Graph Macro

momo6

New Member
Joined
May 24, 2020
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hi guys, how do I modify this macro so it can pick colours from columns B&C, instead of A?
1590964181452.png

'Name macro
Sub ColorChartColumnsbyCellColor()

'The With ... End With statement allows you to write shorter code by referring to an object only once instead of using it with each property.
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection(1)

'Save chart data source range from first chart on worksheet Sheet1
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))

'Iterate through each cell in data source range
For i = 1 To vAddress.Cells.Count

'Copy color from cell to bar
.Points(i).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(vAddress.Cells(i).Interior.ColorIndex)

'Continue with next cell
Next i
End With
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Your macro takes the first set (on the X-axis in the chart) of the first serie.
To obtain the second set of the first serie (ie column B), change this
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
into this:
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(2), "!")(1))

To obtain the second set of the second serie (ie column C), change this
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection(1)
into this:
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection(2)
 
Upvote 0
Your macro takes the first set (on the X-axis in the chart) of the first serie.
To obtain the second set of the first serie (ie column B), change this
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
into this:
Set vAddress = ActiveSheet.Range(Split(Split(.Formula, ",")(2), "!")(1))

To obtain the second set of the second serie (ie column C), change this
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection(1)
into this:
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection(2)
Thanks
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,569
Latest member
Honeymonster123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top