[[20061214123707]] 『マクロでグラフ作成』(ジャイ子) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『マクロでグラフ作成』(ジャイ子)
 マクロの記録を使って、グラフ作成のマクロを作成しています。

 折れ線グラフで、最後の列(平均)は第2軸にします。
 マクロの記録ですと、常に同じ列を参照してしまい、エラーになってしまいます。
 手持ちの本を読んでいるのですが分からず、教えていただきたいのですが・・・

 また、表のタイトルを「○月○日アクセス件数」としたいのですが、この○に入る文字ををシート名(yyyymmddで表示)から自動的に入力することは可能でしょうか?
 (例えば「20061214」というシート名なら「12月14日アクセス件数」です)
 今出来ているマクロは以下のとおりです。

 Sub グラフ作成()

     ActiveSheet.ChartObjects.Add _
        (10, 80, 550, 360).Activate
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData _
        ActiveSheet.Range("A1").CurrentRegion, PlotBy:=xlColumns
    ActiveChart.HasLegend = False '凡例を表示しない

    ActiveChart.PlotArea.Select
    With Selection.Border
        .ColorIndex = 16
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    With Selection.Interior
        .ColorIndex = 2
        .PatternColorIndex = 1
        .Pattern = xlSolid
    End With
    ActiveChart.SeriesCollection(53).Select '平均
    With Selection.Border
        .ColorIndex = 13
        .Weight = xlMedium
        .LineStyle = xlContinuous
    End With
    With Selection
        .MarkerBackgroundColorIndex = xlNone
        .MarkerForegroundColorIndex = xlNone
        .MarkerStyle = xlNone
        .Smooth = False
        .MarkerSize = 3
        .Shadow = False
    End With
    ActiveChart.SeriesCollection(53).AxisGroup = 2 '平均

       ActiveChart.Axes(xlValue).Select
    With ActiveChart.Axes(xlValue)
        .MaximumScale = 2000
    End With
    Selection.TickLabels.AutoScaleFont = False
    With Selection.TickLabels.Font
        .Name = "MS Pゴシック"
        .Size = 8
    End With
    ActiveChart.Axes(xlValue, xlSecondary).Select
    With ActiveChart.Axes(xlValue, xlSecondary)
        .MinimumScale = -500
        .MaximumScale = 1000
    End With
    Selection.TickLabels.AutoScaleFont = False
    With Selection.TickLabels.Font
        .Name = "MS Pゴシック"
        .FontStyle = "標準"
        .Size = 8
    End With
    ActiveChart.Axes(xlCategory).Select
    With ActiveChart.Axes(xlCategory)
        .CrossesAt = 1
        .TickLabelSpacing = 30
        .TickMarkSpacing = 1
        .AxisBetweenCategories = True
        .ReversePlotOrder = False
    End With
    Selection.TickLabels.AutoScaleFont = False
    With Selection.TickLabels.Font
        .Name = "MS Pゴシック"
        .FontStyle = "標準"
        .Size = 8
    End With
    ActiveChart.ChartArea.Select
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "○月○日アクセス件数"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "(時間)"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "(件数)"
        .Axes(xlValue, xlSecondary).HasTitle = True
        .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "(平均アクセス件数)"
    End With
    ActiveChart.ChartTitle.Select
    With Selection.Border
        .Weight = xlHairline
        .LineStyle = xlAutomatic
    End With

    With Selection.Border
        .Weight = xlHairline
        .LineStyle = xlAutomatic
    End With
    Selection.Shadow = True
    Selection.Interior.ColorIndex = xlAutomatic
    Selection.AutoScaleFont = False
    With Selection.Font
        .Name = "MS Pゴシック"
        .FontStyle = "標準"
        .Size = 11

    End With
    ActiveChart.Axes(xlValue).AxisTitle.Select
    Selection.AutoScaleFont = False
    With Selection.Font
        .Name = "MS Pゴシック"
        .FontStyle = "標準"
        .Size = 8
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .ReadingOrder = xlContext
        .Orientation = xlHorizontal
    End With
    ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Select
    Selection.AutoScaleFont = False
    With Selection.Font
        .Name = "MS Pゴシック"
        .FontStyle = "標準"
        .Size = 8
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .ReadingOrder = xlContext
        .Orientation = xlHorizontal
    End With
    ActiveChart.Axes(xlCategory).AxisTitle.Select
    Selection.AutoScaleFont = False
    With Selection.Font
        .Name = "MS Pゴシック"
        .FontStyle = "標準"
        .Size = 8
    End With

 '   レイアウトを整える
    ActiveChart.ChartTitle.Select
    Selection.Left = 215
    Selection.Top = 1
    ActiveChart.PlotArea.Select
    Selection.Left = 1
    Selection.Top = 16
    Selection.Width = 543
    Selection.Height = 323
    ActiveChart.Axes(xlValue).AxisTitle.Select
    Selection.Top = 1
    ActiveChart.Axes(xlValue, xlSecondary).AxisTitle.Select
    Selection.Left = 469
    Selection.Top = 1
    ActiveChart.Axes(xlCategory).AxisTitle.Select
    Selection.Left = 515
    Selection.Top = 341

 End Sub

 >「○月○日アクセス件数」
の部分だけですが、
 Sub TEST_20061216_2()
     Dim myDate As Date
     With ActiveSheet
         If IsNumeric(.Name) And Len(.Name) = 8 Then
             myDate = Format(Val(.Name), "0000/00/00")
             MsgBox Format(myDate, "mm月dd日アクセス件数")
         End If
     End With
 End Sub
 
参考にしてください。
(みやほりん)(-_∂)b

 みやほりん様、ありがとうございました。
 参考にさせていただきます。

 第2軸(平均)の参照については、自力で解決しました。 ((53)→("平均")に置換)

 ありがとうございました。(ジャイ子)

 >自力で解決しました。 
おめでとうございます。
とにかくグラフは苦手なので、突っ込まれたらどうしようかと思ってました。
(みやほりん)(-_∂)b

コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.