1

您好,我已经编写了用于生成图形的代码,并且它工作正常。问题是生成需要花费大量时间。我不明白为什么需要时间。代码是

    Dim cc As Chart

    Set cc = ActiveWorkbook.Charts.Add
    Set cc = cc.Location(Where:=xlLocationAsObject, name:=assume)

    With cc

     .ChartType = xlXYScatterLines

     With .Parent

       .Top = Columns(b).Offset(0, 4).Top
       .Left = Columns(b).Offset(0, 4).Left
       .name = "cc"

     End With

  End With

  Dim sc As Series
  Set sc = cc.SeriesCollection(1)

  With sc
      .Values = Columns(b).Offset(0, -3)
      .XValues = Columns(b).Offset(0, -5)
  End With

请有人帮助我

4

2 回答 2

1

你关掉屏幕更新了吗?将此添加到代码的开头:

Application.ScreenUpdating = False

然后在代码的最后添加:

Application.ScreenUpdating = True
于 2012-10-17T16:49:31.517 回答
1

试试这个,只用实际数据绘制列的行。

Sub makeChart(b As String, assume As String) 'i presupposed these arguments based on your code

Application.ScreenUpdating = False

Dim cc As Chart

Set cc = ActiveWorkbook.Charts.Add
Set cc = cc.Location(Where:=xlLocationAsObject, Name:=assume)

With cc

    .ChartType = xlXYScatterLines

    With .Parent

        .Top = Columns(b).Offset(0, 4).Top
        .Left = Columns(b).Offset(0, 4).Left
        .Name = "cc"

    End With

End With


Dim strValue As String, strXValue As String

'here you are using the passed column letter to find the specific column you want to chart
strValue = Split(Range(b & "1").Offset(, -3).Address, "$")(1) 'will return "C" if given column F
strXValue = Split(Range(b & "1").Offset(, -5).Address, "$")(1) 'will return "A" if given column F

Dim sc As Series
Set sc = cc.SeriesCollection(1)

With sc

    'will select from row 1 to the last true used row in the given column
    .Values = Range(strValue & "1:" & strValue & Range(strValue & Rows.Count).End(xlUp).Row)
    .XValues = Range(strXValue & "1:" & strXValue & Range(strXValue & Rows.Count).End(xlUp).Row)

End With

Application.ScreenUpdating = True

End Sub
于 2012-10-22T13:55:43.533 回答