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

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 に答える