范围(字符串)Excel VBA

时间:2016-09-27 14:35:00

标签: excel vba excel-vba

我正在尝试运行此代码:

// Passing in the current HttpContext into StudentData
services.Add(new ServiceDescriptor(typeof(IStudentData), p => new StudentData(HttpContext.Current), ServiceLifetime.Transient));

但我总是得到:运行时错误'9':下标超出范围。它接缝Range()对象不希望接受myrange String作为输入。如果我使用Range(“R4:S5”)例如......

,代码可以很好地工作

1 个答案:

答案 0 :(得分:0)

Dim myrange As String


For i = LBound(lOffsets) To UBound(lOffsets)
    myrange = "R" & CStr(2 * i + 4) & ":R" & CStr(2 * i + 5) & "," & "S" & CStr(2 * i + 4) & ":S" & CStr(2 * i + 5)
    Set rangeT = Worksheets("ChartBuilder").Range(myrange)

    ActiveSheet.ChartObjects("overview").Chart.SeriesCollection.Add _
     Source:=rangeT
Next i

就像这样。