ExcelのVBAを用いたベクトル分布作成のプログラムです.

需要とかあるんかな?

速度分布とかにどーぞ.

マクロの使い方とかは他のサイト参考にしてくださいm(-_-)m


※値とか色とかはそれぞれに応じて変更してください…


●最初に用意しておくデータの例
しょこたんのブログ


●マクロ実行後
しょこたんのブログ

●プログラム


Sub ベクトル分布作成()

'----------------------------------------------------------------
'シート上に既存のグラフがあれば削除
If ActiveSheet.ChartObjects.Count > 0 Then
For i = 1 To ActiveSheet.ChartObjects.Count
'グラフ名が一致するか
If ActiveSheet.ChartObjects(i).Name = "vector_map" Then
ActiveSheet.ChartObjects(i).Delete
Exit For
End If
Next
End If

'----------------------------------------------------------------
'散布図作成
'位置,サイズ(左端,上端,幅,高さ)
ActiveSheet.ChartObjects.Add(100, 100, 376, 296).Select
Selection.Name = "vector_map"
'グラフの種類
ActiveChart.ChartType = xlXYScatter
'データ範囲(自動で取得),データ系列方向
ActiveChart.SetSourceData Range(Cells(2, 1), Cells(Range("A2").End(xlDown).Row, 2)), xlColumns


'グラフタイトル
ActiveChart.HasTitle = False
'x軸タイトル
ActiveChart.Axes(xlCategory, xlPrimary).HasTitle = False
'y軸タイトル
ActiveChart.Axes(xlValue, xlPrimary).HasTitle = False
'凡例
ActiveChart.HasLegend = False
'x軸
'最小値,最大値,目盛幅,軸表示,目盛線表示
ActiveChart.Axes(xlCategory, xlPrimary).MinimumScale = 0
ActiveChart.Axes(xlCategory, xlPrimary).MaximumScale = 336
ActiveChart.Axes(xlCategory, xlPrimary).MajorUnit = 50
ActiveChart.HasAxis(xlCategory, xlPrimary) = False
ActiveChart.Axes(xlCategory).HasMajorGridlines = False
'y軸
'最小値,最大値,目盛幅,軸の反転,軸表示,目盛線表示
ActiveChart.Axes(xlValue, xlPrimary).MinimumScale = 0
ActiveChart.Axes(xlValue, xlPrimary).MaximumScale = 256
ActiveChart.Axes(xlValue, xlPrimary).MajorUnit = 50
ActiveChart.Axes(xlValue).ReversePlotOrder = True
ActiveChart.HasAxis(xlValue, xlPrimary) = False
ActiveChart.Axes(xlValue).HasMajorGridlines = False


'グラフエリア
'背景色
ActiveSheet.ChartObjects("vector_map").Activate
ActiveChart.ChartArea.Select
Selection.Interior.ColorIndex = xlNone
Selection.Border.ColorIndex = xlNone
'プロットエリア
'左端,上端,幅,高さ,背景色,枠線
ActiveChart.PlotArea.Select
Selection.Left = 15
Selection.Top = 15
Selection.Width = 336
Selection.Height = 256
Selection.Interior.ColorIndex = xlNone
Selection.Border.Color = RGB(0, 0, 0)
'マーカー
'種類,大きさ,色,背景色
ActiveChart.SeriesCollection(1).Select
Selection.MarkerStyle = xlMarkerStyleCircle
Selection.MarkerSize = 7
Selection.MarkerForegroundColor = RGB(255, 0, 0)
Selection.MarkerBackgroundColorIndex = xlNone

'----------------------------------------------------------------
'ベクトル分布作成
'値の取得
For i = 2 To Range("A2").End(xlDown).Row
begin_x = ActiveSheet.Cells(i, 1).Value
begin_y = ActiveSheet.Cells(i, 2).Value
end_x = ActiveSheet.Cells(i, 3).Value
end_y = ActiveSheet.Cells(i, 4).Value


'ベクトル作成
'直線作成,矢印作成,色
ActiveSheet.ChartObjects("vector_map").Activate
ActiveChart.ChartArea.Select
'Excel 2003対応はこっち(左端,上端,幅,高さ)
'ActiveChart.Shapes.AddConnector(msoConnectorStraight, begin_x + 15, begin_y + 15, end_x - begin_x, end_y - begin_y).Select
'Excel 2007対応はこっち(始点,終点)
ActiveChart.Shapes.AddConnector(msoConnectorStraight, begin_x + 15, begin_y + 15, end_x + 15, end_y + 15).Select

Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 255)

Next


End Sub