Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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
Excel 从不同工作表中的数据创建图表时,下标超出范围错误_Excel_Vba_Excel Charts - Fatal编程技术网

Excel 从不同工作表中的数据创建图表时,下标超出范围错误

Excel 从不同工作表中的数据创建图表时,下标超出范围错误,excel,vba,excel-charts,Excel,Vba,Excel Charts,我正在从sheet3的日期在sheet2中创建图表,但将.setsourcedata设置为sheet3时出现“脚本超出范围”错误。如果我没有定义它,它会运行,但会从sheet2打印范围。如果在定义x/y值时添加sheet3,则会出现相同错误: .SeriesCollection(1).XValues = sheet3.Range(Cells(irow, icolumnu), Cells(frowu, icolumnu)) 请帮帮我 Set cht = Sheet2.Shapes.AddChar

我正在从sheet3的日期在sheet2中创建图表,但将.setsourcedata设置为sheet3时出现“脚本超出范围”错误。如果我没有定义它,它会运行,但会从sheet2打印范围。如果在定义x/y值时添加sheet3,则会出现相同错误:

.SeriesCollection(1).XValues = sheet3.Range(Cells(irow, icolumnu), Cells(frowu, icolumnu))
请帮帮我

Set cht = Sheet2.Shapes.AddChart.Chart

With cht
    .ChartType = xlXYScatterSmooth
    .Axes(xlValue).ScaleType = xlScaleLogarithmic
    .SeriesCollection.NewSeries
    .SetSourceData Source:=Worksheets("sheet3").Range(Cells(irow, icolumnu), Cells(frowu, icolumnu + 1))
    .SeriesCollection(1).Name = Sheet3.Cells(2, icolumnu).Value 'upper curve
        '.Name = Sheet3.Cells(2, icolumnu).Value
    .SeriesCollection(1).XValues = Range(Cells(irow, icolumnu), Cells(frowu, icolumnu))
    .SeriesCollection(1).Values = Range(Cells(irow, icolumnu + 1), Cells(frowu, icolumnu + 1))
    'End With
    .SeriesCollection.NewSeries
    .SetSourceData Source:=Worksheets("sheet3").Range(Cells(irow, icolumnl), Cells(frowl, icolumnl + 1))
    .SeriesCollection(2).Name = Sheet3.Cells(2, icolumnl).Value
    .SeriesCollection(2).XValues = Range(Cells(irow, icolumnl), Cells(frowl, icolumnl))
    .SeriesCollection(2).Values = Range(Cells(irow, icolumnl + 1), Cells(frowl, icolumnl + 1))
       ' End With
End With

.
单元格
可以引用任何工作表,在没有限定的情况下,它假定为活动工作表,在本例中,这不是您想要的。您需要明确地告诉它使用与范围使用的工作表相同的工作表。Dooaah谢谢BigBen!