• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:VBAでのグラフの系列の設定について)

VBAでのグラフの系列の設定について

このQ&Aのポイント
  • VBAを使用してグラフの系列設定を行いたい場合、設定内容を変数にすると正常に動作しないことがあります。
  • 特に、線種やマーカースタイルの設定には注意が必要です。
  • 正常に動作させるためには、LST関数の定義に注意し、カラーインデックスの定義を正しく行う必要があります。

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

  • ベストアンサー
  • papayuka
  • ベストアンサー率45% (1388/3066)
回答No.2

> A(変数)="xlContinuous" > .LineStyle = A > という書き方は受け付けてくれないのでしょうか? これではダメでしょう。 xlContinuous 名前付定数で文字列じゃありません。 VBEの表示-オブジェクトブラウザで「xlLineStyle」を検索して、xlContinuousを見てください。 Const xlContinuous = 1 これなら通るでしょう。 .LineStyle = 1 Gotoの多用はソースを解りづらくしますので、控えた方が良いかと思います。

yasujiootani
質問者

お礼

ありがとうございました。

全文を見る
すると、全ての回答が全文表示されます。

その他の回答 (1)

  • papayuka
  • ベストアンサー率45% (1388/3066)
回答No.1

LST や CID などの宣言部分と値をセットしている部分を省略してしまったら、何だかわかりません。 Iも不明ですし、実現されたい事も見えません。 Excel2000だと、LineStyleプロパティに使用出来る定数は下記のいずれかとなってます。 xlContinuous、xlDash、xlDashDot、xlDashDotDot、xlDot、xlDouble、xlSlantDashDot、xlLineStyleNone

yasujiootani
質問者

補足

すみません。 グラフの線種やマーカーを設定するマクロを作ろうと思います。その際、線種・マーカーを記述したシート("系列")から種類を読み取って、設定しようと思います。 KRT(10), LST(10), WGT(10), MST(10), MBC(10), SDW(10),CID(10), MFC(10), MSZ(10)にそれぞれ読み取った設定値を格納しようとしています。 A(変数)="xlContinuous" .LineStyle = A  という書き方は受け付けてくれないのでしょうか? 以下、マクロ。 ---------------------------------------- Sub 系列書式の設定2() Dim SHEETNAME As String Dim KRT(10), LST(10), WGT(10), MST(10), MBC(10), SDW(10) As String Dim CID(10), MFC(10), MSZ(10) As Integer I = 6 J = 2 1 'CONTINUE KRT(J) = Worksheets("系列").Cells(I, 2) LST(J) = Worksheets("系列").Cells(I, 3) CID(J) = Worksheets("系列").Cells(I, 4) WGT(J) = Worksheets("系列").Cells(I, 5) MST(J) = Worksheets("系列").Cells(I, 7) MBC(J) = Worksheets("系列").Cells(I, 8) MFC(J) = Worksheets("系列").Cells(I, 9) MSZ(J) = Worksheets("系列").Cells(I, 10) SDW(J) = Worksheets("系列").Cells(I, 11) If KRT(J) = "" Then GoTo 2 Else I = I + 1: J = J + 1 GoTo 1 End If 2 'CONTINUE KRTMAX = J - 2 SHEETNAME = "ACC": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "VEL": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "DIS": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "RDIS": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "ANGLE": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "SHEAR": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "SC": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU SHEETNAME = "OTM": Worksheets(SHEETNAME).Activate: GoSub KEIRETSU Worksheets("コントロール").Select End KEIRETSU: ActiveSheet.ChartObjects("グラフ 1").Activate NN = ActiveChart.SeriesCollection.Count If NN - 1 <> KRTMAX Then MsgBox ("グラフの系列の数と定義されている系列の数が異なる") End End If For I = 1 To NN KEIRETUNAME = ActiveChart.SeriesCollection(I).Name 'MsgBox KEIRETUNAME ActiveChart.SeriesCollection(I).Select If I = 1 Then GoTo 3 With Selection.Border ' .LineStyle = LST(I + 1) ' .ColorIndex = CID(I + 1) ' .WEIGHT = WGT(I + 1) .LineStyle = xlContinuous .ColorIndex = 1 .WEIGHT = xlThin End With With Selection ' .MarkerStyle = MST(I + 1) ' .MarkerBackgroundColorIndex = MBC(I + 1) ' .MarkerForegroundColorIndex = MFC(I + 1) ' .MarkerSize = MSZ(I + 1) ' .Shadow = SDW(I + 1) ' .Smooth = False .MarkerStyle = xlDiamond .MarkerBackgroundColorIndex = 48 .MarkerForegroundColorIndex = 1 .MarkerSize = 5 .Shadow = False .Smooth = False End With 3 'CONTINUE '********** ダミー系列の書式設定 If KEIRETUNAME = "DUMMY" Then ActiveChart.SeriesCollection(I).Select With Selection.Border .WEIGHT = xlThin .LineStyle = xlNone End With With Selection .MarkerBackgroundColorIndex = xlAutomatic .MarkerForegroundColorIndex = xlAutomatic .MarkerStyle = xlNone .Smooth = False .MarkerSize = 5 .Shadow = False End With End If Next I ActiveSheet.Cells(1, 1).Select Return End Sub

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • VBAで表作成

    こんにちわ VBAを使い表を作っているのですが、入力フォームで日付を入力しコマンドボタンを押すと別ブックになり、予め用意してある表に入力した日付から1ヶ月の日付が貼り付けるというのをやっています。 マクロを記録し試してみたところ構文エラーが出てしまいました。 日付を貼り付けるところまでできたのですが・・・ 表には線がすでに入っています。 入力された最後の日付のところで太線で表を閉めたいのですができますでしょうか。 構文エラーになったソースを貼り付けます。 Range((4,"i"+12):(10,"i"+12)).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With よろしくお願いします

  • エクセルVBAで罫線挿入

    マクロの記録で下記のように記録されたものを簡潔にまとめるにはどのように記述したらいいでしょうか? Range("C3:F3").Select 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 .HorizontalAlignment = xlCenterAcrossSelection .VerticalAlignment = xlBottom End With

  • 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

  • Excel2003枠を作るマクロ

    右側に空白の行を一つつくって枠を作りたいです。 たとえば、G100が一番右下とするとH100まで枠を作りたいのですが、きれいにかくにはどうしたらよいでしょうか? マクロ記録でやると、下のようになるのですが右下が100で有るとは限らないのでその行を定義する必要があると思うのですが、そのあたりがさっぱりわかりません。 よろしくお願いいたします。 Sub Macro1() Selection.End(xlDown).Select Range("H100").Select Range(Selection, Selection.End(xlUp)).Select Range(Selection, Selection.End(xlToLeft)).Select Range(Selection, Selection.End(xlToLeft)).Select Range(Selection, Selection.End(xlToLeft)).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

  • エクセル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

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

    ワークシートのセルの書式設定の罫線をマクロでひく。 下記マクロを実行すると  (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

  • このマクロコードをダイエットするには?

    罫線を引き、配色し、文字に色を付ける。 このコードをどのようにダイエットすればよいのでしょうか? 罫線のマクロはこんなに大きいのですか? Withの使い方がよくわかりません。 よろしくお願い致します。 ------------ Sub Test1() Range("B1:O14").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlHairline .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlHairline .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 With Selection.Interior .ColorIndex = 56 .Pattern = xlSolid End With Selection.Font.ColorIndex = 33 End Sub

  • VBA 選択範囲の中で、更に一番上の行を指定したい!

    タイトルの通りです。 選択範囲に罫線を引くマクロを作成しました。 外に太い枠線、中は点線を引き、選択範囲の一番上の行を灰色の塗りつぶしにしたいのです。 しかし、罫線はうまくいきましたが、一番上の行の指定がうまくできません。 Sub 罫線をひく() ' With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlHairline End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlHairline End With ActiveWindow.SmallScroll Down:=12  ←ここを変えたいのですが、どうすればよいかわかりません。 With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorDark1 .TintAndShade = -0.499984740745262 .PatternTintAndShade = 0 End With End Sub どうすればよいか、もしご存知の方がいらっしゃいましたら、ご指導ください。 よろしくお願いたします。

  • エクセル マクロ VBA 罫線 文字列

    職場で使う表をVBAマクロを用いて罫線作成をしています。 前任者のアレンジを頼まれたのですが前任者に連絡が取れず困っています。 表の特徴は以下のようになります。 ・A列を飛ばし、B列から2列飛びで文字を記入 ・b2=曜日、b3=1、b4=2、b5=3、b6=4、b7=空白のセットが曜日ごとに2セット×7日分 この表を ・b2=曜日、b3=-3、b4=-2、b5=-1、b6=0、b7=1、b8=2、b9=3、b10=4、b11=空白のセットが曜日ごとに2セット×7日分 に変更したいのですが空欄の場所がずれてしまい上手くいきません。 原本のマクロは以下です。 ---------------------------------------------------------------- Sub 罫線作成() Range(Cells(4, 1), Cells(86, 22)).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone Selection.Borders(xlEdgeBottom).LineStyle = xlNone Selection.Borders(xlEdgeRight).LineStyle = xlNone Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone ch1 = "月火水木金土日" For i = 4 To 76 Step 12 n1 = (i + 8) \ 12 Range(Cells(i, 1), Cells(i + 10, 22)).Select With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlMedium .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 'Cells(i, 1) = Mid(ch1, n1, 1) For i2 = 2 To 20 Step 3 For i3 = i To i + 10 nb1 = (i3 + 8) Mod 12 If nb1 = 0 Or nb1 = 6 Then Cells(i3, i2) = Mid(ch1, n1, 1) If nb1 = 1 Or nb1 = 7 Then Cells(i3, i2) = 1 If nb1 = 2 Or nb1 = 8 Then Cells(i3, i2) = 2 If nb1 = 3 Or nb1 = 9 Then Cells(i3, i2) = 3 If nb1 = 4 Or nb1 = 10 Then Cells(i3, i2) = 4 Next Next Next End Sub ---------------------------------------------------------------- 4行目から142行目まで使用することは分かっているのですが… どうかご助力お願いします。

  • エクセルでデータがある部分だけ罫線で囲いたいです。

    エクセルでデータがある部分だけ罫線で囲いたいです。 エクセルのファイルを開いて、データのある部分だけを罫線で囲みたいです。 データーは常に列数も行数も違います。 マクロの記録で行ったら、以下のようになりました。 もう少し短い文章ではできないでしょうか? Sub Macro1() ' ' Macro1 Macro ' マクロ記録日 : 2010/9/22 ' Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).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