0

在下面的代码中

Sub SetColorScheme(cht As Chart, i As Long)

    Dim y_off As Long, rngColors As Range
    Dim x As Long

    y_off = i Mod 10
    'this is the range of cells which has the colors you want to apply
    Set rngColors = ThisWorkbook.Sheets("colors").Range("A1:C1").Offset(y_off, 0)

    With cht.SeriesCollection(1)
        'loop though the points and apply the 
        'corresponding  fill color from the cell
        For x = 1 To .Points.Count
            .Points(x).Format.Fill.ForeColor.RGB = _
                             rngColors.Cells(x).Interior.Color
        Next x
    End With

End Sub

读取数据的范围在代码中说明。是否有可能从工作表中的表格中读取?这样一个人就可以输入 A1:C1 并且它会立即按照代码中的方式放置它?

4

2 回答 2

1

我不确定您想如何处理用户的输入,但当然范围可以是传入变量。我将它作为字符串在下面,但优雅将是范围对象。对不起,如果这太简单了,我不确定你的问题。

Sub SetColorScheme(UserRange As String, cht As Chart, i As Long)
    ...

    'this is the range of cells which has the colors you want to apply
    Set rngColors = ThisWorkbook.Sheets("colors").Range(UserRange).Offset(y_off, 0)

    ...    
End Sub
于 2013-07-05T22:26:07.813 回答
0

如果用户在单元格 D1 中输入“A1:C1”,那么您可以通过以下方式使用此范围:

Set rngColors = ThisWorkbook.Sheets("colors").Range(Range("D1").Value).Offset(y_off, 0)
' but you should refer to the w/sheet as well

Set rngColors = ThisWorkbook.Sheets("colors") _ 
    .Range(ThisWorkbook.Sheets("colors").Range("D1").Value).Offset(y_off, 0)

Range("D1").Value获取文本“A1:C1”,然后用于标识此范围。

于 2013-07-05T23:58:27.967 回答