VBAのグラフの設定について

このQ&Aのポイント
  • VBAを使用して、散布図の設定を線ありにし、終点を矢印にしたいです。
  • 設定の際には線はかけるものの、矢印の設定に関してエラーが発生しています。
  • 正しい設定方法を教えてください。
回答を見る
  • ベストアンサー

VBAのグラフの設定について

散布図の設定を線ありにし、かつ終点を矢印にしたいのですが、線はかけるものの、矢印の設定の時、 With Sheet1.ChartObjects("Chart").Chart.SeriesCollection(1) .Border.LineStyle = xlContinuous '線の種類(連続線) End With With sheet1.ChartObjects("Chart").ShapeRange .Line.EndArrowheadStyle = msoArrowheadOpen End With と設定すると、指定された値は境界を超えています。とでます。いくつかの方法でやりましたが、オブジェクトが対象ではないなど、エラーがどうしてもでてしまいます。どのように設定したら良いでしょうか?

質問者が選んだベストアンサー

  • ベストアンサー
  • queuerev2
  • ベストアンサー率78% (96/122)
回答No.1

当方Excel2007ですが、 With sheet1.ChartObjects("Chart").ShapeRange .Line.EndArrowheadStyle = msoArrowheadOpen End With のかわりに With Sheet1.ChartObjects("Chart").Chart.SeriesCollection(1) .Format.Line.EndArrowheadStyle = msoArrowheadOpen End With としたらエラーは出ずに散布図の線の終点に矢じりがつきました。

参考URL:
http://officetanaka.net/excel/vba/graph/17.htm
kinakosansan
質問者

お礼

エラーがでずに矢印を付けることができました。大変助かりました!ありがとうございます。

関連するQ&A

  • エクセルVBAでグラフの線とマーカを設定したい

    エクセルVBAでグラフの線とマーカを設定したいです。 グラフの線は無しでマーカの線が有りにしたいのですが、 マクロで記録したコードを見ると グラフの線、マーカの線ともにFormat.Line.Visibleで指定しています。 実際にコードを記述しても、以下の様になり、グラフの線が表示されてしまいます。 ChartObjects("1").Chart.SeriesCollection(10).Format.Line.Visible = msoFalse With ChartObjects("1").Chart.SeriesCollection(10).Format.Line .Visible = msoTrue .ForeColor.RGB = RGB(255, 102, 0) .Transparency = 0 End With グラフの線は無しでマーカの線が有りに設定は出来ないのでしょうか?

  • VBA罫線

    VBA罫線 a = 9 With Range(Cells(3, 2), Cells(a, 5)) .Borders(xlEdgeTop).LineStyle = xlContinuous .Borders(xlEdgeBottom).LineStyle = xlContinuous .Borders(xlEdgeRight).LineStyle = xlContinuous .Borders(xlEdgeLeft).LineStyle = xlContinuous .Borders(xlInsideVertical).LineStyle = xlContinuous .Borders(xlInsideHorizontal).LineStyle = xlContinuous End With どこのワークシートかを指定する場合はどうしたらいいのでしょうか?

  • エクセルVBA 行列の数を指定して罫線を引くマクロ教えてください

    下のようにSheet1に罫線を引く「開始セル(左右端)」「行」「列」が書いてあります。 この条件で罫線をSheet2に引くようにしたいのですが、変数の設定の仕方などが分かっていないようで、できません。教えていただけないでしょうか。マクロの記録をとったところ、下のようになりました。よろしくお願いします。 開始セル Sheet2!A1・・・Sheet1のB1セル 行 8・・・Sheet1のB2セル 列 2・・・Sheet1のB3セル Sub borders() Range("A1:B8").Select Selection.borders(xlDiagonalDown).LineStyle = xlNone Selection.borders(xlDiagonalUp).LineStyle = xlNone With Selection.borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End Sub

  • BorderクラスのLinestyleプロパティを設定できません

    いつもお世話になります。 VBAでB9からE24に罫線を引いてたのですが、急にエラーが出るようになりました。 今までは出ませんでしたが、2003で使用しだしてから、 出たり、出なかったりします。 作成 winxp Office2002で、 使用は別端末 winxp Office2003です。 コードはマクロの記録より引用。 シート保護はしていません。 [メッセージ]  実行時エラー'1004':  BorderクラスのLinestyleプロパティを設定できません。 [コード] Range("B9:E24").Select With Selection.Borders(xlEdgeLeft)   .LineStyle = xlContinuous <--※※   .Weight = xlThin End With With Selection.Borders(xlEdgeTop)   .LineStyle = xlContinuous   .Weight = xlThin End With With Selection.Borders(xlEdgeBottom)   .LineStyle = xlContinuous   .Weight = xlThin End With With Selection.Borders(xlEdgeRight)   .LineStyle = xlContinuous   .Weight = xlThin End With With Selection.Borders(xlInsideVertical)   .LineStyle = xlContinuous   .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal)   .LineStyle = xlContinuous   .Weight = xlThin End With With Selection.Borders(xlEdgeLeft)   .LineStyle = xlContinuous   .Weight = xlMedium End With With Selection.Borders(xlEdgeTop)   .LineStyle = xlContinuous   .Weight = xlMedium End With With Selection.Borders(xlEdgeBottom)   .LineStyle = xlContinuous   .Weight = xlMedium End With With Selection.Borders(xlEdgeRight)   .LineStyle = xlContinuous  .Weight = xlMedium End With With Selection.Borders(xlInsideVertical)   .LineStyle = xlContinuous   .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal)   .LineStyle = xlContinuous   .Weight = xlThin End With F8で一行づつ実行しても.LineStyle、.weightの全行で引っかかります。 解決策ご存知の方、宜しくお願い致します。

  • Excel VBAで罫線を引くマクロを書きたい

    Excel VBAで罫線を引くマクロを書きたいと思っています。 で、文末のコードを書きました。(というかマクロ記録したものほぼそのもの) これだとある程度動くのですが、内側線が無いような範囲を選択した場合にはエラーになってしまいます。 内側の線を引く際にIF文をかまさなければならないように思うのですが、イマイチわかりません。 この点について教えてください。 また、コードが冗長であるようにも思えます。もう少しスマートな書き方があればあわせて教えてください。 よろしくお願いします。 Sub 枠線基本() ' 周囲 With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With ' 内側 With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With End Sub

  • [VBA Excel] 2系列の散布図を書いてみるとおかしくなります・・・

    Excel 2007とVBAで数値解析をしています。計算結果のグラフを表示するための準備段階として、次のようなプログラムを組んで、2系列の散布図を書いて見ました。 Option Explicit Sub makechart()   Dim chart1 As ChartObject, wsh As Worksheet   Set wsh = Sheet1   Set chart1 = wsh.ChartObjects.Add( _   10, 20, 250, 200)   With chart1.Chart    .ChartType = xlLineStacked    .SeriesCollection.NewSeries    .SeriesCollection(1).XValues = _     wsh.Range("A1:A5")    .SeriesCollection(1).Values = _     wsh.Range("B1:B5")   End With   With chart1.Chart    .SeriesCollection.NewSeries    .SeriesCollection(2).XValues = _     wsh.Range("A1:A5")    .SeriesCollection(2).Values = _     wsh.Range("C1:C5")   End With End Sub --sheet1--   A B C ----------- 1| 1 2 3 2| 2 3 4 3| 3 4 5 4| 4 5 6 5| 5 6 7 系列1のグラフはB列 対 A列という意図通りのものになったのですが、系列2のグラフは、Y軸の値が、C列の値にB列の値を足したもの (1,2+3)、(2,3+4) ・・・ になってしまいました。系列2のグラフも純粋にC列 対 A列したいのですが、そのためにはどうすれば良いでしょうか。ご教授ください。

  • VBAでのグラフ作成時の色づけ方法

    VBAを使用して散布図を作成しているのですが、 その散布図のマーカーの色をすべて同じ色にするプログラムを考えています。 以下のプログラムを実行してみたのですが色が変更されないため、 どなたか教えていただけると嬉しいです。 よろしくお願いします。 Sub グラフ作成と色づけ() Dim i As Integer With Sheet1.ChartObjects.Add(100, 50, 300, 200).Chart .ChartType = xlXYScatter .SetSourceData Source:=Sheets("sheet1").Range("C2:DD4465") .HasTitle = True .ChartTitle.Characters.Text = "気温変化" .HasLegend = False .HasDataTable = False For i = 1 To 105 .SeriesCollection(i).Interior.ColorIndex = 3 Next i End With MsgBox ("FINISH") End Sub

  • VBAでの質問

    散布図で表示した要素ChartObjects.Chart.SeriesCollection(1).Points(2)のExcel上の座標を取得するにはどうしたらいいでしょうか?

  • ワークシートのセルの書式設定の罫線をマクロでひく。

    ワークシートのセルの書式設定の罫線をマクロでひく。 下記マクロを実行すると  (1)のところでBORDERクラスのlinestyle プロパティを設定できません。がでる対策をおしえてください。 Sub Macro1() ' Dim d As Long Sheets("abc").Select '罫線を引く d = Range("A65536").End(xlUp).Row Range("A1", Cells(d, 1)).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous  ‘(1) .Weight = xlThin .ColorIndex = xlAutomatic End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With End Sub

  • ExcelのVBAの保護をかけた時のグラフについて教えてください。

    グラフにタイトルを設定した後、保護をかけると「ChatクラスのHasTitleプロパティを設定できません」といわれてしまい、.HasTitle=Trueで止まってしまいました。シートの保護をかけても動くようにしたいのですが、どうしたらよいのでしょうか。 (保護しなければ通常に動きます。) 'グラフをオブジェクトで配置 set chartObj=worksheets("Sheet1").ChartObjects.Add(200,0,300,200) chartObj.Chart.SetSourceData Worksheets("Sheet1").range(range("b4").End(xlDown),ActiveCell.end(xlToright)) 'タイトルをつける with worksheets("Sheet1").ChartObjects(1).Chart .HasTitle=True .ChartTitle.Text="タイトル" End with 保護をかけてもグラフの作成ができるのに、タイトル部分で止まってしまうのはなぜでしょうか。 よろしくお願い致します。

専門家に質問してみよう