<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>グラフ作成 | VBA・GAS・Pythonで仕事を楽しく効率化</title>
	<atom:link href="https://officevba.info/category/excelvba/excel%E6%93%8D%E4%BD%9C/%E3%82%B7%E3%83%BC%E3%83%88%E3%81%AE%E6%93%8D%E4%BD%9C/%E3%82%B0%E3%83%A9%E3%83%95%E4%BD%9C%E6%88%90/feed/" rel="self" type="application/rss+xml" />
	<link>https://officevba.info</link>
	<description>仕事の役に立つVBA・GAS・Pythonのコードを紹介していきます。</description>
	<lastBuildDate>Tue, 01 Jan 2019 04:25:03 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>

<image>
	<url>https://officevba.info/wp-content/uploads/2017/04/cropped-Excel_1-32x32.jpg</url>
	<title>グラフ作成 | VBA・GAS・Pythonで仕事を楽しく効率化</title>
	<link>https://officevba.info</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>たくさんのレーダーチャートを一括で作成するExcelVBA</title>
		<link>https://officevba.info/radarchart-making/</link>
					<comments>https://officevba.info/radarchart-making/#respond</comments>
		
		<dc:creator><![CDATA[okumasahito]]></dc:creator>
		<pubDate>Sat, 10 Nov 2018 15:02:48 +0000</pubDate>
				<category><![CDATA[グラフ作成]]></category>
		<guid isPermaLink="false">http://officevba.info/?p=1571</guid>

					<description><![CDATA[目次 グラフもVBAで自動作成できる種類の指定→サイズの指定→タイトルや凡例の設定→範囲の設定の順序でグラフ作成グラフを作成する対象シートレーダーチャートを連続作成するExcelVBA グラフもVBAで自動作成できる 先 [&#8230;]]]></description>
										<content:encoded><![CDATA[
  <div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">グラフもVBAで自動作成できる</a></li><li><a href="#toc2" tabindex="0">種類の指定→サイズの指定→タイトルや凡例の設定→範囲の設定の順序でグラフ作成</a></li><li><a href="#toc3" tabindex="0">グラフを作成する対象シート</a></li><li><a href="#toc4" tabindex="0">レーダーチャートを連続作成するExcelVBA</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">グラフもVBAで自動作成できる</span></h2>
<p>先日、ある層の社員に対するアンケート結果をグラフにする仕事がありました。<br />
アンケートは対象の社員が仕事や日常生活に対してどのように考えているのかを把握する目的で作られており、各個人ごとのアンケート結果を面談時の資料にするのですが、限られた時間で多くの社員の状況を把握できるようにレーダーチャートを作ってほしいとの要望です。</p>
<p>対象となる社員の数が多い（約100人）ため、手作業でグラフを作るのが大変だったので、VBAを使用してグラフを作成する方法を考えました。<br />
今回はその時に勉強して作った複数のレーダーチャートを一括で作成するExcelVBAを紹介します。</p>
<h2><span id="toc2">種類の指定→サイズの指定→タイトルや凡例の設定→範囲の設定の順序でグラフ作成</span></h2>
<p>グラフの作成はいくつかのステップで構成されていて、マクロの記録で作成したVBAコードは順序がバラバラに記録作成されるため解読しにくいです。<br />
今回レーダーチャートを作成するにあたっては下記の手順で作成することにします。</p>
<li>①グラフの種類の指定</li>
<li>②グラフサイズの指定</li>
<li>③グラフのタイトル・凡例の設定</li>
<li>④自動で作成されるグラフ範囲の削除</li>
<li>⑤グラフ範囲の設定</li>
<p>グラフを作成する際、範囲をあらかじめ設定してから作成しても良いのですが、たくさんのグラフを一括で作成する場合、余計な部分が多くなるのでまず対象範囲を空に戻して必要なグラフ範囲のみ設定することにしています。</p>
<h2><span id="toc3">グラフを作成する対象シート</span></h2>
<p>今回グラフを作成する際に使用する表は下記のようなものです。</p>
<p><a href="https://officevba.info/wp-content/uploads/2018/11/116.jpg"><img fetchpriority="high" decoding="async" src="https://officevba.info/wp-content/uploads/2018/11/116-700x489.jpg" alt="116" width="680" height="475" class="alignnone size-large wp-image-1576" srcset="https://officevba.info/wp-content/uploads/2018/11/116-700x489.jpg 700w, https://officevba.info/wp-content/uploads/2018/11/116-300x209.jpg 300w, https://officevba.info/wp-content/uploads/2018/11/116-768x536.jpg 768w, https://officevba.info/wp-content/uploads/2018/11/116-320x223.jpg 320w, https://officevba.info/wp-content/uploads/2018/11/116.jpg 1282w" sizes="(max-width: 680px) 100vw, 680px" /></a></p>
<p>アンケートは対象者1名につき2回実施しており、それぞれの実施回において平均点も算出しています。<br />
レーダーチャートは対象者1人ごとに1個作成するので、2回分の結果とそれぞれの平均も載せるように作成します。</p>
<h2><span id="toc4">レーダーチャートを連続作成するExcelVBA</span></h2>
<p>今回作成したレーダーチャートを一括作成するExcelVBAのコードは下記の通りです。<br />
少しずつ位置をずらしながら繰り返してグラフを作成する仕様になっております。</p>
<div class="VBACode">Sub レーダーグラフ一括作成()</p>
<p><span class="VBA_Tab1">Dim グラフ</span></p>
<p><span class="VBA_Tab1">i = 1</span><br />
<span class="VBA_Tab1">Do Until Cells(i + 2, 2) = &#8220;&#8221;</span><br />
<span class="VBA_Tab2">Set グラフ = ActiveSheet.Shapes.AddChart2(317, xlRadar) <span class="VBA_Comment">’マーカーなしレーダーグラフ</span></span></p>
<p><span class="VBA_Tab2">With グラフ <span class="VBA_Comment">’グラフ位置の設定</span></span><br />
<span class="VBA_Tab3">.Top = Range(Rows(1), Rows(2)).Height + Range(Rows(3), Rows(7)).Height * (i － 1)</span><br />
<span class="VBA_Tab3">.Left = Range(Columns(1), Columns(14)).Width</span><br />
<span class="VBA_Tab3">.Width = Range(Columns(15), Columns(19)).Width</span><br />
<span class="VBA_Tab3">.Height = Range(Rows(3), Rows(7)).Height － 1.5</span></p>
<p><span class="VBA_Tab3">With .Chart</span></p>
<p><span class="VBA_Tab4">.HasTitle = True <span class="VBA_Comment">’タイトルを表示する</span></span><br />
<span class="VBA_Tab4">.ChartTitle.Text = Cells(i + 2, 1) &amp; &#8221; &#8221; &amp; Cells(i + 2, 2)</span></p>
<p><span class="VBA_Tab4">.HasLegend = True <span class="VBA_Comment">’凡例を表示する</span></span><br />
<span class="VBA_Tab4">.Legend.Position = xlLegendPositionRight <span class="VBA_Comment">’凡例を右に表示する</span></span></p>
<p><span class="VBA_Tab4">.Axes(xlValue).MajorUnit = 1 <span class="VBA_Comment">’グラフの主目盛を設定する</span></span></p>
<p><span class="VBA_Tab4">Do Until .SeriesCollection.Count = 0 <span class="VBA_Comment">’自動でグラフ範囲設定される場合があるので削除しておく</span></span><br />
<span class="VBA_Tab5">.SeriesCollection(1).Delete</span><br />
<span class="VBA_Tab4">Loop</span></p>
<p><span class="VBA_Tab4">.SeriesCollection.NewSeries <span class="VBA_Comment">’系列（1回目）の追加</span></span><br />
<span class="VBA_Tab4">With .FullSeriesCollection(1)</span><br />
<span class="VBA_Tab5">.Name = &#8220;=Sheet1!&#8221; &amp; Cells(2, 1).Address</span><br />
<span class="VBA_Tab5">.Values = &#8220;=Sheet1!&#8221; &amp; Range(Cells(i + 2, 3), Cells(i + 2, 9)).Address</span><br />
<span class="VBA_Tab5">.XValues = &#8220;=Sheet1!&#8221; &amp; Range(Cells(2, 3), Cells(2, 9)).Address <span class="VBA_Comment">’レーダーチャートの項目軸設定</span></span><br />
<span class="VBA_Tab5">.Border.Color = RGB(0, 0, 255)</span><br />
<span class="VBA_Tab4">End With</span></p>
<p><span class="VBA_Tab4">.SeriesCollection.NewSeries <span class="VBA_Comment">’系列（2回目）の追加</span></span><br />
<span class="VBA_Tab4">With .FullSeriesCollection(2)</span><br />
<span class="VBA_Tab5">.Name = &#8220;=Sheet1!&#8221; &amp; Cells(10, 1).Address</span><br />
<span class="VBA_Tab5">.Values = &#8220;=Sheet1!&#8221; &amp; Range(Cells(i + 10, 3), Cells(i + 10, 9)).Address</span><br />
<span class="VBA_Tab5">.Border.Color = RGB(255, 0, 0)</span><br />
<span class="VBA_Tab4">End With</span></p>
<p><span class="VBA_Tab4">.SeriesCollection.NewSeries <span class="VBA_Comment">’系列（平均1回目）の追加</span></span><br />
<span class="VBA_Tab4">With .FullSeriesCollection(3)</span><br />
<span class="VBA_Tab5">.Name = &#8220;平均&#8221; &amp; Cells(2, 1)</span><br />
<span class="VBA_Tab5">.Values = &#8220;=Sheet1!&#8221; &amp; Range(Cells(8, 3), Cells(8, 9)).Address</span><br />
<span class="VBA_Tab5">.Border.LineStyle = xlDot <span class="VBA_Comment">’点線</span></span><br />
<span class="VBA_Tab5">.Border.Weight = xlHairline  <span class="VBA_Comment">’極細</span></span><br />
<span class="VBA_Tab5">.Border.Color = RGB(50, 50, 255)</span><br />
<span class="VBA_Tab4">End With</span></p>
<p><span class="VBA_Tab4">.SeriesCollection.NewSeries <span class="VBA_Comment">’系列（平均2回目）の追加</span></span><br />
<span class="VBA_Tab4">With .FullSeriesCollection(4)</span><br />
<span class="VBA_Tab5">.Name = &#8220;平均&#8221; &amp; Cells(10, 1)</span><br />
<span class="VBA_Tab5">.Values = &#8220;=Sheet1!&#8221; &amp; Range(Cells(16, 3), Cells(16, 9)).Address</span><br />
<span class="VBA_Tab5">.Border.LineStyle = xlDot</span><br />
<span class="VBA_Tab5">.Border.Weight = xlHairline</span><br />
<span class="VBA_Tab5">.Border.Color = RGB(255, 50, 50)</span><br />
<span class="VBA_Tab4">End With</span><br />
<span class="VBA_Tab3">End With</span></p>
<p><span class="VBA_Tab2">End With</span><br />
<span class="VBA_Tab2">Set グラフ = Nothing</span><br />
<span class="VBA_Tab1">i = i + 1</span><br />
<span class="VBA_Tab1">Loop</span></p>
<p>End Sub</p></div>
<p>値の参照位置は式で「=Sheet1!$C$3:$I$3」などのような記載方法しかないので、変数部分はアドレス関数を用いて変換しています。</p>
<p>他のグラフの作成手順はまた別の機会にご紹介します。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://officevba.info/radarchart-making/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
