【问题标题】:Changing the colors of the specific dots in scatterplot vba excel更改散点图vba excel中特定点的颜色
【发布时间】:2013-04-05 14:19:58
【问题描述】:

我想更改散点图左上角的点颜色。 我写了一个宏,没有发生错误但颜色没有改变:/

Sub Kolorowanie()
ActiveSheet.ChartObjects("Chart 1").Activate
a = ActiveChart.SeriesCollection(1).Values
b = ActiveChart.SeriesCollection(1).XValues

For i = LBound(a) To UBound(a)

If a(i) < 0 And b(i) > 0 Then
  ActiveSheet.ChartObjects("Chart 1").Activate
  ActiveChart.SeriesCollection(1).Select
  ActiveChart.SeriesCollection(1).Points(i).Select
   With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 0, 0)
    .Solid
   End With

Else
End If
Next i
End Sub

任何想法为什么它不起作用?

【问题讨论】:

    标签: excel vba colors scatter


    【解决方案1】:

    摆脱.Solid 或者把它放在之前你设置Forecolor.RGB,我认为这是覆盖某些东西(我注意到这个和其他一些错误/无法执行某些操作甚至因为宏记录器会使这些方法看起来应该正常工作)。

    Option Explicit
    Sub Kolorowanie()
    Dim cht As Chart
    Dim srs As Series
    Dim pt As Point
    
    Set cht = ActiveSheet.ChartObjects(1).Chart
    
    Set srs = cht.SeriesCollection(1)
    
    For Each pt In srs.Points
        With pt.Format.Fill
            .Visible = msoTrue
            '.Solid  'I commented this out, but you can un-comment and it should still work
            .ForeColor.RGB = RGB(255, 0, 0)
    
        End With
    Next
    
    
    End Sub
    

    或者:

    For Each pt In srs.Points
    With pt.Format.Fill
        .Visible = msoTrue
        .Solid  'This is the default so including it doesn't do anything, but it should work either way.
        .ForeColor.RGB = RGB(255, 0, 0)
    
    End With
    Next
    

    将此应用于您的代码会给我们:

    Sub Kolorowanie()
    ActiveSheet.ChartObjects("Chart 1").Activate
    a = ActiveChart.SeriesCollection(1).Values
    b = ActiveChart.SeriesCollection(1).XValues
    
    For i = LBound(a) To UBound(a)
    
    If a(i) < 0 And b(i) > 0 Then
       ActiveSheet.ChartObjects("Chart 1").Activate
       ActiveChart.SeriesCollection(1).Select
       ActiveChart.SeriesCollection(1).Points(i).Select
       With Selection.Format.Fill
            .Visible = msoTrue
            .Solid
            .ForeColor.RGB = RGB(255, 0, 0)
    
       End With
    
    Else
    End If
    Next i
    End Sub
    

    【讨论】:

    • 太棒了——很高兴它有效。如果它解决了您的问题,请考虑“接受”答案。干杯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多