0

I have looked around the web for a while and tried different things, not worked. I have a set of data that will vary in length all in different sheet, I wrote a macro to put all of them in one sheet, now they all have different number of rows. I'm trying to put all of them onto a graph but I get stuck when specifying the range. All help would be kindly appreciated, bellow is the code that I manipulated from a recorded Macro:

Sub charttest()

    Dim r As Range
    Set r = ActiveSheet.Range("A1").CurrentRegion

    Range("D9").Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("'OBA 1'!$A$1" & "r.Columns.Coun, r.Rows.Coun")
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
End Sub
4

2 回答 2

0

我审查了我的工作并更新了我的代码,因为我不再满足我的需求,我将代码分成几部分运行,并使用上面的方法,我的图表函数最终出现错误 13,我确定错误来自源行。任何人都可以建议我遵循的道路吗?

Sub t_feuille(f_Work As Worksheet)

Dim num_line As Integer, t_Work As Worksheet
Dim myrange As Range

'instals time column
f_Work.Activate
f_Work.Cells(1, 1) = "Time"
For num_line = 2 To last_line(t_Work)
  f_Work.Cells(num_line, 1) = num_line - 2
Next

'graph set up

  Set myrange = ActiveSheet.Cells(1, 1).CurrentRegion
  Application.CutCopyMode = False
  ActiveChart.ChartWizard _
    Source:=Sheets(f_Work).Range(myrange), _
    Gallery:=xlXYScatterSmoothNoMarkers, Format:=4, PlotBy:=xlColumns, _
    CategoryLabels:=1, SeriesLabels:=1, HasLegend:=1, _
    Title:=f_Work, CategoryTitle:="", _
    ValueTitle:="", ExtraTitle:=""

End Sub

Function last_line(f_Work) As Integer
Dim num_col As Integer, num_line As Integer

  num_line = 0
  For num_col = 1 To ActiveSheet.Cells(1, 10000).End(xlToLeft).Column
    If ActiveSheet.Cells(100000, num_col).End(xlUp).Row > num_line Then
      num_line = ActiveSheet.Cells(100000, num_col).End(xlUp).Row
    End If
Next

  last_line = num_line
End Function
于 2013-07-11T09:48:29.563 回答
0

尝试更改以下行:

ActiveChart.SetSourceData Source:=Range("'OBA 1'!$A$1" & "r.Columns.Coun, r.Rows.Coun")

进入(假设ActivesheetOBA 1表:

ActiveChart.SetSourceData Source:=r

或进入(在其他情况下):

ActiveChart.SetSourceData Source:=Range("'OBA 1'!" & r.Address)
于 2013-06-04T21:29:50.990 回答