调用图表过程时出现无效的过程调用错误

调用图表过程时出现无效的过程调用错误

问题描述:

有人会猜测我为什么会收到“运行时错误5:无效的过程调用或参数?” 图表工作正常,只是我得到此错误,我想要摆脱它。调用图表过程时出现无效的过程调用错误

Option Explicit 
Option Base 1 

Sub dort9() 

Dim cMin As Double 
Dim cMax As Double 
Dim lDer As Long 
Dim NoIntervals As Long 
Dim plaga() As Variant 
Dim i As Long 
Dim J As Long 

Dim dest As Range 
Dim A As Integer 
Dim B As Integer 
Dim rColumn() As Variant 
Dim result() As Variant 
ReDim result(1 To 4) 
ReDim result2(1 To 4) 


NoIntervals = 4 
ReDim Preserve plaga(14) 

    With Worksheets("Sheet1") 
     plaga = .Range(.Cells(1, 1), .Cells(14, 1)).Value 
    End With 

Call tri1(plaga) 

cMin = WorksheetFunction.Min(plaga) 
cMax = WorksheetFunction.Max(plaga) 

Dim longInter As Double 
longInter = (cMax - cMin)/NoIntervals 

ReDim plaga2(1 To NoIntervals) As Long 
ReDim arrIntervals(1 To NoIntervals) 

Dim pla As Variant 
Dim lCom As Long 
Dim res As Variant 

    For i = 1 To NoIntervals 
     arrIntervals(i) = cMax - ((i - 1) * longInter) 
    Next i 

    For Each pla In plaga 
     res = Application.Match(pla, arrIntervals, -1) 
     plaga2(res) = plaga2(res) + 1 
    Next pla 


    result(1) = plaga2(1) 

    For B = 2 To 4 
     result(B) = (plaga2(B) + result(B - 1)) 
    Next B 

    For A = 1 To 4 
     result2(A) = WorksheetFunction.Round((result(A)/14) * 100, 2) & " %" 
    Next A 

    Set dest = Worksheets("Sheet1").Range("D1") 
    dest.Resize(4, 1).Value = Application.Transpose(result2) 
    Call ChartNew2(result2) 

End Sub 

它有它调用图表上从数组...第一次调用程序是无关紧要的,它工作正常绘制值的最后一次通话过程中。

Sub ChartNew2(result2 As Variant) 
Dim i As Integer 
ReDim result2(1 To 4, 1 To 1) 
Charts.Add 

    For i = LBound(result2, 1) To UBound(result2, 1) 
     result2(i, 1) = result2 
    Next i 
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers 
    ActiveChart.Location Where:=xlLocationAsObject 

    With ActiveChart 
      .HasTitle = True 
      .Axes(xlValue, xlPrimary).HasTitle = True 
    End With 


    With ActiveChart.Axes(xlValue) 
       .HasMajorGridlines = True 
    End With 

    ActiveChart.HasLegend = False 
    ActiveChart.PlotArea.Select 

    Selection.Interior.ColorIndex = xlAutomatic 
    ActiveChart.Axes(xlValue).Select 

    With ActiveChart.Axes(xlValue) 

      .MaximumScale = 1 

    End With 

End Sub 
+0

您将需要从'ChartNew2()' – 2013-04-27 07:11:51

+0

发布相关的代码,在那里声明'result2'变量以及哪种方式?尝试在“call”行之前停止过程,而不是使用F8键进行调试。你知道数组'result2'似乎是用ZERO打包的... – 2013-04-27 08:33:37

定位方法'其中'参数和'名称'参数。 如果Where等于'xlLocationAsObject',那么Name是必需的。所以你必须指定名称来定位方法调用。

Sub ChartNew2() 

    ' Creates a new chart sheet and returns a Chart object 
    Dim newChart As Variant 
    Set newChart = ActiveWorkbook.Charts.Add 

    With newChart 
     ' Name is required if Where is xlLocationAsObject 
     .Location Where:=xlLocationAsObject, Name:="Sheet1" 
     ' ... 
    End With 
End Sub