2012-07-17 66 views
0

的問題與錯誤條似乎是解決了,但現在我gettng一個錯誤5.錯誤行是:錯誤13 errorbar擅長

ActiveChart.SeriesCollection(1).ApplyDataLabels自動圖文集:=假LegendKey :=假ShowSeriesName:=假ShowCategoryName:=假ShowValue:=真,_ ShowPercentage:=假ShowBubbleSize:=假

'resize chart 
WS.ChartObjects(1).Width = 500 
WS.ChartObjects(1).Height = chartmultipl * (rowcnt - 1 - minscale) 
WS.ChartObjects(1).Left = chartleftpos 
WS.ChartObjects(1).Top = 70 
'Rescale values to positions in chart so that labels can be succesfully moved 
minchar = ActiveChart.Axes(xlCategory).MinimumScale 
maxchar = ActiveChart.Axes(xlCategory).MaximumScale 
midchar = (maxchar + minchar)/2 
'datalabels 
ActiveChart.SeriesCollection(1).ApplyDataLabels AutoText:=False, LegendKey:=False, ShowSeriesName:=False, ShowCategoryName:=False, ShowValue:=True, _ 
    ShowPercentage:=False, ShowBubbleSize:=False 
For i = 1 To rowcnt - 1 
    If WS.Cells(i + 1, labelcol) <> "" Then 
     With ActiveChart.SeriesCollection(1).Points(i).DataLabel 
      .Characters.Text = Left(WS.Cells(i + 1, labelcol).Value, 28) 
      .AutoScaleFont = False 
      With .Characters(Start:=1, Length:=100).Font 
       .Name = "Arial" 
       If WS.Cells(i + 1, labelcol).Font.Italic = True Then 
        .FontStyle = "Italic" 
       ElseIf WS.Cells(i + 1, labelcol).Font.Bold = True Or Not ptype Then 
        .FontStyle = "Bold" 
       Else 
        .FontStyle = "Normal" 
       End If 
       .Size = labelsize 
       .Strikethrough = False 
       .Superscript = False 
       .Subscript = False 
       .OutlineFont = False 
       .Shadow = False 
       .Underline = xlUnderlineStyleNone 
       .ColorIndex = xlAutomatic 
      End With 
      'move labels wherever there is enough space to display them or to the beginning of the graph 
      If ptype Then 
       textsize = Application.WorksheetFunction.Min(Len(WS.Cells(i + 1, labelcol).Value), 28) 
       If WS.Cells(i + 1, int1).Value <= midchar Then 
        .Left = 15 + Round(ActiveChart.PlotArea.Width * (WS.Cells(i + 1, 6).Value - minchar)/(maxchar - minchar)) 
       Else 
        .Left = -textsize * 3 + Round(ActiveChart.PlotArea.Width * (WS.Cells(i + 1, 5).Value - minchar)/(maxchar - minchar)) 
       End If 
      Else 
       .Left = 20 
      End If 
     End With 
    End If 
Next i 
'if it's an outcome graph use set square sizes, if a final MA graph use study weights 
If Not ptype Then 
    For i = 1 To resultcount 
     With ActiveChart.SeriesCollection(1).Points(i) 
      .MarkerSize = Round(sqsize(i), 0) 
     End With 
    Next i 
End If 
'send chart to back for future merging 
WS.ChartObjects(1).SendToBack 
'ActiveChart.ChartArea.Select 
'Selection.ShapeRange.ZOrder msoSendToBack 
'deselect graph so that I can add the rest of the shapes but first save things that are needed 
minsc = ActiveChart.Axes(xlCategory).MinimumScale 
maxsc = ActiveChart.Axes(xlCategory).MaximumScale 
WS.Range("A1").Select 
'if it is the final scatterplot add the diamonds 
If Not ptype Then 
    Dim plarealeft, plarearight As Double 
    Dim dheight, incrh As Double 
    Dim origleft, origlength, transleft As Double 
    Dim diampos, diamlength As Double 
    Dim grtop As Double 
    'left and right edge of plot area in pixels 
    plarealeft = 371 
    plarearight = 827 
    'diamond statistics 
    dheight = 10 
    'vertical alignment of diamonds - increment from one to another 
    incrh = WS.ChartObjects(1).Height/((rowcnt - 1) - minscale + 2) 
    'top of the graph 
    grtop = WS.ChartObjects(1).Top 
    'get all info in tables so that I can use in loops 
    mu(1) = fe_mu 
    mu(2) = dl_mu 
    mu(3) = ml_mu 
    mu(4) = pl_mu 
    mu(5) = T_mu 
    mvar(1) = fe_var 
    mvar(2) = dl_var 
    mvar(3) = ml_var 
    mvar(4) = pl_var 
    mvar(5) = T_var 
    For i = 1 To 4 
     tmargin(i) = 1.96 
    Next i 
    tmargin(5) = Excel.WorksheetFunction.TInv(0.05, resultcount - 1) 
    tlabel(1) = "FE" 
    tlabel(2) = "DL" 
    tlabel(3) = "ML" 
    tlabel(4) = "PL" 
    tlabel(5) = "T" 
    'go through all 5 diamonds 
    For i = 1 To 5 
     'original length and far left position 
     origleft = mu(i) - tmargin(i) * (mvar(i)^(1/2)) 
     origlength = 2 * tmargin(i) * (mvar(i)^(1/2)) 
     'transform to [0,1] scale 
     transleft = (origleft - minsc)/(maxsc - minsc) 
     'transform to points 
     diampos = plarealeft + (plarearight - plarealeft) * transleft + 1 
     diamlength = (plarearight - plarealeft) * origlength/(maxsc - minsc) 
     ActiveSheet.Shapes.AddShape(msoShapeDiamond, diampos, grtop + (rowcnt - 1.5 + i + 1) * incrh - dheight/2, diamlength, dheight).Select 
     Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 0, 0) 
     ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, diampos + diamlength + 10, grtop + (rowcnt - 1.5 + i + 1) * incrh - dheight/2, 20, 12).Select 
     Selection.Characters.Text = tlabel(i) 
     With Selection.ShapeRange 
      .Fill.Visible = msoFalse 
      .Line.Visible = msoFalse 
     End With 
     With Selection.Font 
      .Name = "Arial" 
      .FontStyle = "Bold" 
      .Size = 9 
     End With 
    Next i 
End If 
'add text files with study information 
If ptype Then 
    tboxend = rowcnt * 10 
    tboxstep = (tboxend - 80)/(rowcnt - 2) 
    For i = 2 To rowcnt 
     If (WS.Cells(i, 1).Value <> "" And WS.Cells(i - 1, 1).Value = "") Or i = 2 Then 
      'find how many outcomes there are in each study to better align the text boxes 
      j = i 
      Do 
       j = j + 1 
      Loop Until WS.Cells(j, 1).Value = "" 
      cntr = j - i 
      'create textbox 
      tboxpos = tboxend - (i - 2) * tboxstep - (cntr - 1) * tboxstep/2 
      ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 500, tboxpos, 60, 25).Select 
      Selection.Characters.Text = WS.Cells(i, 1).Value 
      With Selection.ShapeRange 
       .Fill.Visible = msoFalse 
       .Line.Visible = msoFalse 
      End With 
      With Selection.Font 
       .Name = "Arial" 
       .FontStyle = "Bold" 
       .Size = 10 
       .Strikethrough = False 
       .Superscript = False 
       .Subscript = False 
       .OutlineFont = False 
       .Shadow = False 
       .Underline = xlUnderlineStyleNone 
       .ColorIndex = xlAutomatic 
      End With 
     End If 
    Next i 
End If 
'create a list with all the shapes that need to be selected and group them 
j = 0 
For Each Sh In WS.Shapes 
    If Not Left(Sh.Name, 7) = "Comment" Then 
     j = j + 1 
     ReDim Preserve sharray(j) 
     sharray(j) = Sh.Name 
    End If 
Next Sh 
WS.Shapes.Range(sharray).Group 
'deselect shape 
WS.Range("A1").Select 
Application.ScreenUpdating = True 

末次

+0

對不起,您能否告訴我們導致錯誤的行,而不是讓我們仔細梳理50行代碼? – JimmyPena 2012-07-17 17:29:39

+0

是的,錯誤行標有* – user1532500 2012-07-17 17:54:57

+0

ErrorBar方向:=心連心,包括:= xlBoth,類型:= xlCustom,金額:= EDATA,MinusValues:= EDATA – user1532500 2012-07-17 17:55:47

回答

1

首先要做的事情,來幫助追蹤錯誤是正確定義所有變量。

比如:你的第一線

Dim rowcnt, textsize, cntr, labeltop As Integer 

其實是一樣的:

Dim rowcnt as Variant 
Dim textsize as Variant 
dim cntr as Variant 
dim labeltop As Integer 

這樣做可能會彈出其他錯誤,可以幫助你追查是什麼原因造成的線路故障

+0

謝謝你,我修改了你的建議之後的代碼,但仍然在同一行發現錯誤。 – user1532500 2012-07-17 19:15:43

+0

使用修改的代碼編輯原始帖子。哈哈! – 2012-07-17 19:35:42

+0

哈!得到它了!謝謝你:-)但現在我得到錯誤5「無效的過程調用或參數」這裏再次是代碼,錯誤行在最後,用*** – user1532500 2012-07-17 19:44:11

0

在代碼頂部聲明Option Explicit,它將幫助您編寫更好的代碼,方法是強制您聲明所有變量並幫助您更輕鬆地識別錯誤。

這可能導致您的無效調用或參數錯誤:

'get the last row of data 
rowcnt = LASTINCOLUMN2(6, k) 

除非你有一個名爲LASTINCOLUMN2自定義函數,你沒有張貼?

爲了讓最後一排使用:

rowcnt = WS.Range("B" & Rows.Count).End(xlUp).Row 

申報ROWCNT爲Long不是integer

您需要定義: ptype resultcount vareffects

編輯:我仍然通過您的代碼運行,並識別許多身份不明的潛艇/功能。代碼還有第二部分嗎?

+0

函數LASTINCOLUMN2(ByVal clmn As Long,ByVal k As Integer ),只要 昏暗WorkRange作爲範圍 昏暗CellCount,我只要 Application.Volatile 集WorkRange =工作表(k)的.Columns(clmn).EntireColumn 集WorkRange =相交(WorkRange.Parent.UsedRange,WorkRange) CellCount = WorkRange.Count 對於i = CellCount要1個步驟-1 如果不爲IsEmpty(WorkRange(ⅰ))然後 LASTINCOLUMN2 = WorkRange(ⅰ).Row 退出功能 ë nd If Next i End Function – user1532500 2012-07-17 20:00:01

+0

在原始問題中發佈附加代碼,以便閱讀:) – 2012-07-17 20:00:33

+0

這對您有幫助嗎?代碼是用於元分析的,所以在創建圖表之前有很多。讓我知道你是否想要整個thisn,或者如果有特定的變量,你想我發佈。再次感謝 – user1532500 2012-07-17 20:01:22