Hi All!
Would appreciate any help or advice anyone could pass on - would be highly appreciated! I have tried to attempt to solve this myself but I have no VBA knowledge and have not found anything on the internet.
What I'm trying to do is create a macro which takes cell (row) colour from a dataset and make the colours the same within a bar chart etc. I have found some coding but it takes the very first cell within a range and locks it - what I need is for the colour to change on certain rows (i.e. weekend data - yellow, weekday - blue).
The coding
I have found is as follows:
[TABLE="width: 369"]
<colgroup><col><col><col span="3"></colgroup><tbody>[TR]
[TD][TABLE="width: 326"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]Thursday[/TD]
[TD]09 January 2014[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]Friday[/TD]
[TD]10 January 2014[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]Saturday[/TD]
[TD]11 January 2014[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]Sunday[/TD]
[TD]12 January 2014[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]Monday[/TD]
[TD]13 January 2014[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]Tuesday[/TD]
[TD]14 January 2014[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]Wednesday[/TD]
[TD]15 January 2014[/TD]
[TD]22[/TD]
[/TR]
[TR]
[TD]Thursday[/TD]
[TD]16 January 2014[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]Friday[/TD]
[TD]17 January 2014[/TD]
[TD]26[/TD]
[/TR]
[TR]
[TD]Saturday[/TD]
[TD]18 January 2014[/TD]
[TD]57[/TD]
[/TR]
[TR]
[TD]Sunday[/TD]
[TD]19 January 2014[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]Monday[/TD]
[TD]20 January 2014[/TD]
[TD]33[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]I need the weekends within the bar chart to be one colour (represented by whatever colour is in the cell, the weekdays by another colour.
Hope this make some sense - thank you to anyone who could help me - huge thanks!
[/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Would appreciate any help or advice anyone could pass on - would be highly appreciated! I have tried to attempt to solve this myself but I have no VBA knowledge and have not found anything on the internet.
What I'm trying to do is create a macro which takes cell (row) colour from a dataset and make the colours the same within a bar chart etc. I have found some coding but it takes the very first cell within a range and locks it - what I need is for the colour to change on certain rows (i.e. weekend data - yellow, weekday - blue).
The coding
I have found is as follows:
- Sub CellColorsToChart()
- Dim oChart As ChartObject
- Dim MySeries As Series
- Dim FormulaSplit As Variant
- Dim SourceRange As Range
- Dim SourceRangeColor As Long
-
- 'Loop through all charts in the active sheet
- For Each oChart In ActiveSheet.ChartObjects
-
- 'Loop through all series in the target chart
- For Each MySeries In oChart.Chart.SeriesCollection
-
- 'Get Source Data Range for the target series
- FormulaSplit = Split(MySeries.Formula, ",")
-
- 'Capture the first cell in the source range then trap the color
- Set SourceRange = Range(FormulaSplit(2)).Item(1)
- SourceRangeColor = SourceRange.Interior.Color
-
- On Error Resume Next
- 'Coloring for Excel 2003
- MySeries.Interior.Color = SourceRangeColor
- MySeries.Border.Color = SourceRangeColor
- MySeries.MarkerBackgroundColorIndex = SourceRangeColor
- MySeries.MarkerForegroundColorIndex = SourceRangeColor
-
- 'Coloring for Excel 2007 and 2010
- MySeries.MarkerBackgroundColor = SourceRangeColor
- MySeries.MarkerForegroundColor = SourceRangeColor
- MySeries.Format.Line.ForeColor.RGB = SourceRangeColor
- MySeries.Format.Line.BackColor.RGB = SourceRangeColor
- MySeries.Format.Fill.ForeColor.RGB = SourceRangeColor
-
- Next MySeries
- Next oChart
-
- End Sub
[TABLE="width: 369"]
<colgroup><col><col><col span="3"></colgroup><tbody>[TR]
[TD][TABLE="width: 326"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]Thursday[/TD]
[TD]09 January 2014[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]Friday[/TD]
[TD]10 January 2014[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]Saturday[/TD]
[TD]11 January 2014[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]Sunday[/TD]
[TD]12 January 2014[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]Monday[/TD]
[TD]13 January 2014[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]Tuesday[/TD]
[TD]14 January 2014[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]Wednesday[/TD]
[TD]15 January 2014[/TD]
[TD]22[/TD]
[/TR]
[TR]
[TD]Thursday[/TD]
[TD]16 January 2014[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]Friday[/TD]
[TD]17 January 2014[/TD]
[TD]26[/TD]
[/TR]
[TR]
[TD]Saturday[/TD]
[TD]18 January 2014[/TD]
[TD]57[/TD]
[/TR]
[TR]
[TD]Sunday[/TD]
[TD]19 January 2014[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]Monday[/TD]
[TD]20 January 2014[/TD]
[TD]33[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]I need the weekends within the bar chart to be one colour (represented by whatever colour is in the cell, the weekdays by another colour.
Hope this make some sense - thank you to anyone who could help me - huge thanks!
[/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]