2017-06-26 18 views
1

タイトルが示すように、コードはActiveChartが選択される前に行が見つかってもそれを見つけられません。どうすれば修正できますか?データメンバのメンバーが見つかりませんVBA

Sub makeChart(myArr As Variant, title As String) 
    Dim cht As Chart 
    Dim sht As Worksheet 

    Set sht1 = Sheets("Action Register") 
    sht1.Shapes.AddChart.Select 

    Set cht = sht.ActiveChart 
    With ActiveChart 
    .Parent.Top = Range("D20").Top 'Places chart onto specified area 
    .Parent.Left = Range("D20").Left 
    .Parent.Width = Range("D20:V20").Width 
    .Parent.Height = Range("D20:D29").Height 

    .ChartType = xlAreaStacked 
    .SeriesCollection.NewSeries 
    .SeriesCollection(1).Name = "=""Machine""" 
    .SeriesCollection(1).XValues = Application.Index(myArr, , 1) 
    .SeriesCollection(1).Values = Application.Index(myArr, , 2) 
    .SeriesCollection.NewSeries 
    .SeriesCollection(2).Name = "=""Handling""" 
    .SeriesCollection(2).Values = Application.Index(myArr, , 3) 
    .SeriesCollection.NewSeries 
    .SeriesCollection(3).Name = "=""Fiber""" 
    .SeriesCollection(3).Values = Application.Index(myArr, , 4) 
    .SeriesCollection.NewSeries 
    .SeriesCollection(4).Name = "=""Process""" 
    .SeriesCollection(4).Values = Application.Index(myArr, , 5) 
    .SeriesCollection.NewSeries 
    .SeriesCollection(5).Name = "=""Other""" 
    .SeriesCollection(5).Values = Application.Index(myArr, , 6) 'Legends and writes in values for graph 

    .Axes(xlCategory, xlPrimary).HasTitle = True 'Labels 
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Months" 
    .Axes(xlValue, xlPrimary).HasTitle = True 
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Rate(m)" 
    .ChartArea.Font.Size = 20 

    End With 
End Sub 
+0

ワークシートには「ActiveChart」プロパティがありません。 'ActiveChart'または' Application.ActiveChart'だけを使用してください – Rory

答えて

0

トップの右の私は、ワークシートがActiveChart性質を持っていないこれらの2つの過ち

Dim sht1 As Sheets <-------- you forgot this (not sht as Worksheet) 
Set sht1 = Sheets("Action Register") 
sht1.Shapes.AddChart.Select 

Set cht = sht.ActiveChart <-------------- you got your naming all wrong here 
+0

DimとSheetsとWorksheetsの違いは何ですか? – JMinow

+0

sht> sht1という名前(申し訳ありませんが、それはまったくわかりません)、シートオブジェクトにもチャートを含めることができます。 –

1

を見ることができます。 ActiveChartまたはApplication.ActiveChartを使用してください。

関連する問題