Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
彩色图表-VBA Excel 2007-堆叠图表中反映的数据源颜色_Vba_Colors_Charts_Excel 2010 - Fatal编程技术网

彩色图表-VBA Excel 2007-堆叠图表中反映的数据源颜色

彩色图表-VBA Excel 2007-堆叠图表中反映的数据源颜色,vba,colors,charts,excel-2010,Vba,Colors,Charts,Excel 2010,我的工作表包含几个条形图,这些图表的源数据是彩色编码的,并且在同一工作表上。我有下面的代码,我希望能将图表中的条带颜色转换为与源数据相同的颜色,但它不起作用,它只是将所有条带变成白色。有人知道为什么这个代码不起作用并且颜色不匹配吗?非常感谢您能提供的任何帮助。我正在使用excel 2010。多谢各位 请把准确的密码寄出去。 提前谢谢 谢谢你指出…这是代码 Sub CellColorsToChart() Dim oChart As ChartObject Dim MySeries As Seri

我的工作表包含几个条形图,这些图表的源数据是彩色编码的,并且在同一工作表上。我有下面的代码,我希望能将图表中的条带颜色转换为与源数据相同的颜色,但它不起作用,它只是将所有条带变成白色。有人知道为什么这个代码不起作用并且颜色不匹配吗?非常感谢您能提供的任何帮助。我正在使用excel 2010。多谢各位

请把准确的密码寄出去。 提前谢谢

谢谢你指出…这是代码

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

“我有下面的代码,我希望…”这代码在哪里?@TobiMcNamobi请回答…事实是,我不是VBA程序员,一点也不是。但这将增加有人提供帮助的机会。还要注意格式化和添加标记(我现在都这么做了)。也许(对于VBA程序员来说)您正在操作的单元格的示例屏幕截图也会有所帮助。@TobiMcNamobi-非常感谢您的建议…@simoco-请帮助我完成上述代码。。。