2016-03-29 9 views
0

ExcelのVBAで動的グラフを作成しようとしています。残念ながら、グラフを生成すると、y軸の値はシリーズ名になります。 Here's the graph。私は非常に新しいVBAユーザーですので、私はちょうど非常に基本的なエラーを見落としていると確信しています。ここに私のコードです。VBAが間違ってシリーズ名として入力されています

Sheets("Sheet1").Activate 

Dim lRow As Long 
Dim lCol As Long 

'Find the last non-blank cell in column G and H 
Range("G3:H500").Select 
Do Until ActiveCell.Value = "" 
ActiveCell.Offset(1, 0).Select 
Loop 
lastrow = ActiveCell.Row - 1 

'Find the last non-blank cell in row 1 
lCol = Cells(1, Columns.Count).End(xlToLeft).Column 

MsgBox "Last Row: " & lastrow & vbNewLine & _ 
     "" & Columns(lCol).Address(False, False) 

Set rng = Range("G3:H300" & lastrow) 
Set xrang = Range("F3:F300" & lastrow) 

rng.Select 

ActiveSheet.Shapes.AddChart.Select 
ActiveChart.ApplyChartTemplate (_ 
    "c:\users\name\appdata\Roaming\Microsoft\Templates\Charts\brand_line_chart.crtx" _ 
    ) 
ActiveChart.SetSourceData Source:=Range("G3:H300" & lastrow) 
ActiveChart.Axes(xlCategory).Select 
ActiveChart.SeriesCollection(1).XValues = Range("F3:F300" & lastrow) 

ご協力いただきありがとうございます。ありがとうございます。

答えて

0

この行を削除してください。ActiveChart.SeriesCollection(1).XValues =範囲( "F3:F300" & lastrow)。また、ラストローデータを取得しているので、( "G3:H300" &ラストロー)を( "G3:H" &ラストロー)に変更してください。どこにでもこれを設定してください

+0

ありがとうございます!それは問題を解決しました! – Ceterisbearibus

関連する問題