<?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>位置  |  独学エクセル塾</title>
	<atom:link href="https://dokugakuexcel.com/tag/%E4%BD%8D%E7%BD%AE/feed/" rel="self" type="application/rss+xml" />
	<link>https://dokugakuexcel.com</link>
	<description>初心者から中級者までシステム・関数・VBAを伝授します</description>
	<lastBuildDate>Mon, 17 Oct 2022 13:58:12 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://dokugakuexcel.com/wp-content/uploads/2021/06/cropped-cropped-image-66-1-32x32.jpg</url>
	<title>位置  |  独学エクセル塾</title>
	<link>https://dokugakuexcel.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">194648711</site>	<item>
		<title>【マクロVBA】複数の2次配列内（Variant)のセル・指定位置に数値・文字を入力・出力する方法</title>
		<link>https://dokugakuexcel.com/%e3%80%90%e3%83%9e%e3%82%af%e3%83%advba%e3%80%91%e8%a4%87%e6%95%b0%e3%81%ae2%e6%ac%a1%e9%85%8d%e5%88%97%e5%86%85%ef%bc%88%ef%bd%96ariant%e3%81%ae%e3%82%bb%e3%83%ab%e3%83%bb%e6%8c%87%e5%ae%9a%e4%bd%8d/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25e3%2580%2590%25e3%2583%259e%25e3%2582%25af%25e3%2583%25advba%25e3%2580%2591%25e8%25a4%2587%25e6%2595%25b0%25e3%2581%25ae2%25e6%25ac%25a1%25e9%2585%258d%25e5%2588%2597%25e5%2586%2585%25ef%25bc%2588%25ef%25bd%2596ariant%25e3%2581%25ae%25e3%2582%25bb%25e3%2583%25ab%25e3%2583%25bb%25e6%258c%2587%25e5%25ae%259a%25e4%25bd%258d</link>
					<comments>https://dokugakuexcel.com/%e3%80%90%e3%83%9e%e3%82%af%e3%83%advba%e3%80%91%e8%a4%87%e6%95%b0%e3%81%ae2%e6%ac%a1%e9%85%8d%e5%88%97%e5%86%85%ef%bc%88%ef%bd%96ariant%e3%81%ae%e3%82%bb%e3%83%ab%e3%83%bb%e6%8c%87%e5%ae%9a%e4%bd%8d/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[matsu]]></dc:creator>
		<pubDate>Wed, 13 Jul 2022 14:18:44 +0000</pubDate>
				<category><![CDATA[便利技]]></category>
		<category><![CDATA[マクロVBA応用・便利技]]></category>
		<category><![CDATA[Variant]]></category>
		<category><![CDATA[配列]]></category>
		<category><![CDATA[２次配列]]></category>
		<category><![CDATA[位置]]></category>
		<category><![CDATA[セル]]></category>
		<guid isPermaLink="false">https://dokugakuexcel.com/?p=3356</guid>

					<description><![CDATA[マクロVBAの機能には配列というとても便利な機能が存在します。 しかし「data(5)」のように複数の配列の中から数値・文字を入力・出力するには悩まれる方も多いのではないでしょうか。 そこで今回は複数の2次配列内の入力・ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>マクロVBAの機能には<strong><span class="marker-under">配列</span></strong>というとても便利な機能が存在します。</p>



<p>しかし「data(5)」のように<strong><span class="marker-under">複数の配列の中から数値・文字を入力・出力</span></strong>するには<br>悩まれる方も多いのではないでしょうか。</p>



<p>そこで今回は<strong><span class="marker-under">複数の2次配列内の入力・出力方法</span></strong>について紹介したいと思います。<br>それでは見ていきましょう。</p>




  <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">&#x2b1b;︎こんなことができるようになる。</a></li><li><a href="#toc2" tabindex="0">&#x2b1b;︎通常の2次配列内の指定位置・セルの文字を入出力する</a></li><li><a href="#toc3" tabindex="0">&#x2b1b;︎連続した2次配列内の指定位置・セルに入力・出力をする方法</a></li><li><a href="#toc4" tabindex="0">&#x2b1b;︎まとめ</a></li></ol>
    </div>
  </div>

<h2 class="wp-block-heading"><span id="toc1">&#x2b1b;︎こんなことができるようになる。</span></h2>



<p>・複数の２次配列内の指定位置・セルの文字数値を入力・出力できるようになる</p>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-1024x464.png" alt="" class="wp-image-3363" width="527" height="238" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-1024x464.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-300x136.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-768x348.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26.png 1105w" sizes="(max-width: 527px) 100vw, 527px" /></figure>



<h2 class="wp-block-heading"><span id="toc2">&#x2b1b;︎通常の2次配列内の指定位置・セルの文字を入出力する</span></h2>



<p>まず初めに<strong><span class="marker-under">通常の2次配列内の指定した位置・セルから文字・数値を出力、または入力</span></strong>してみましょう。<br>見本で以下のシートを用意しました。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="237" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-20-1024x237.png" alt="" class="wp-image-3357" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-20-1024x237.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-20-300x69.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-20-768x178.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-20.png 1077w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>内容としては<span class="bold-red">「B3からE5」</span>までを配列に格納して<br><strong><span class="marker-under-red">配列内</span></strong>に入力したのち、<span class="bold-blue">「G3からJ5」</span>に貼り付けます。</p>



<p>プログラムはこのようになります。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Sub 配列見本()</p><p>Dim<span class="marker-under-red"> Data</span></p><p><span class="marker-under-red">Data </span>=<span class="bold-red"> Range(&#8220;B3:E5&#8221;)</span></p><p><span class="bold-blue">Range(&#8220;G3:J5&#8221;)</span> =<span class="marker-under-red"> Data</span></p><p>End Sub</p></blockquote>



<p>実行した結果こちら。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="239" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-21-1024x239.png" alt="" class="wp-image-3358" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-21-1024x239.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-21-300x70.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-21-768x179.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-21.png 1100w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>上手く配列に格納して、貼り付けもできています。<br>では配列内の指定位置に数値を入力するプログラムを作成していきましょう。</p>



<p>例えば3行目の５列目にあたる、<strong><span class="marker-under">「E3」は「cells(3,5)」</span></strong>ですが、同じ要領で<br>2次配列に格納した<strong><span class="marker-under">3行目の５列目は「変数名（3,5）」</span></strong>となります。</p>



<p>では再度見本を見ていきましょう。<br><span class="bold-red">「B3からE5」</span>を配列に格納して配列内の<strong><span class="marker-under">2行目の3行目</span></strong>に<span class="bold-green">「123」</span>を入力し、<br><span class="bold-blue">「G3からJ5」</span>に格納した配列を出力します。</p>



<p>プログラムはこのようになります。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Sub 配列見本()</p><p>Dim<span class="marker-under-red"> Data</span></p><p><span class="marker-under-red">Data</span> = <span class="bold-red">Range(&#8220;B3:E5&#8221;)</span><br><span class="marker-under-red">Data</span><span class="marker-under">(2, 3) </span>=<span class="bold-green"> 123</span></p><p><span class="bold-blue">Range(&#8220;G3:J5&#8221;)</span> = <span class="marker-under-red">Data</span></p><p>End Sub</p></blockquote>



<p>実行した結果はこちらです。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="265" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-22-1024x265.png" alt="" class="wp-image-3359" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-22-1024x265.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-22-300x78.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-22-768x199.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-22.png 1079w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>格納した配列に変数に文字・数値を入力して、その配列を<br>別のセルに貼り付けることができるようになりました。</p>



<p>　</p>



<p>こちらの方法は処理の<strong><span class="marker-under">高速化にも応用</span></strong>できます。<br>例えばセル内の文字数値の計算をする際に計算する回数が多ければ<br>処理速度は遅くなってしまいます。</p>



<p>そこで計算したい数値を配列に格納して<br>配列内で計算させて、最後にセルに出力することで、<br>処理速度はとても速くなります。</p>



<p>詳しい方法については下記リンクに貼り付けてますので是非参考にしてみてください。</p>



<p><a href="https://dokugakuexcel.com/%e3%80%90vba%e7%9f%a5%e8%ad%98-%e9%ab%98%e9%80%9f%e5%8c%96%e2%91%a1%e3%80%91%e3%81%82%e3%81%be%e3%82%8a%e7%9f%a5%e3%82%89%e3%82%8c%e3%81%a6%e3%81%84%e3%81%aa%e3%81%84%ef%bc%9f%e5%a4%a7%e9%87%8f/">【マクロVBA知識 高速化②】あまり知られていない？大量データで処理が遅いマクロVBAを高速化 ► 独学エクセル塾 (dokugakuexcel.com)</a></p>



<h2 class="wp-block-heading"><span id="toc3">&#x2b1b;︎連続した2次配列内の指定位置・セルに入力・出力をする方法</span></h2>



<p>では<strong><span class="marker-under">連続した2次配列の方法</span></strong>を見てみましょう。<br>例えば「N(5)」のようにNという配列を5つ活用することができます。</p>



<p>例を見ていきましょう。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="854" height="407" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-23.png" alt="" class="wp-image-3360" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-23.png 854w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-23-300x143.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-23-768x366.png 768w" sizes="(max-width: 854px) 100vw, 854px" /></figure>



<p>「B2からE3」「B5からE6」「B8からE9」「B11からE12」「B14からE15」を<br><span class="bold-red">N</span>という配列に格納してみましょう。</p>



<p>そして出力したい配列を変数「<span class="bold-blue">Number</span>」で指定したいとします。<br>プログラムはこのようになります。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Sub 二次配列見本()</p><p>Dim <span class="bold-red">N</span>(5), Number As Long</p><p><span class="bold-blue">Number </span>= 2 &#8216;表示したい配列番号を入力</p><p>　</p><p><span class="bold-red">N</span>(1) = Range(&#8220;B2:E3&#8221;)<br><span class="bold-red">N</span>(2) = Range(&#8220;B5:E6&#8221;)<br><span class="bold-red">N</span>(3) = Range(&#8220;B8:E9&#8221;)<br><span class="bold-red">N</span>(4) = Range(&#8220;B11:E12&#8221;)<br><span class="bold-red">N</span>(5) = Range(&#8220;B14:E15&#8221;)</p><p>　</p><p>Range(&#8220;G8:J9&#8221;) = <span class="bold-red">N</span>(<span class="bold-blue">Number</span>)</p><p>End Sub</p></blockquote>



<p>今回は変数「<span class="bold-blue">Number</span>」を<span class="bold-blue">2</span>で実行してみましょう。<br>結果はこのようになります。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="468" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-24-1024x468.png" alt="" class="wp-image-3361" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-24-1024x468.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-24-300x137.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-24-768x351.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-24.png 1114w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>N（2）の配列を貼り付けることができました。<br>さらに「<span class="bold-blue">number</span>」を<span class="bold-blue">4</span>で実行すると、、、</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Sub 二次配列見本()</p><p>Dim N(5), Number As Long</p><p><span class="bold-blue">Number</span> = 4 &#8216;表示したい配列番号を入力</p><p>N(1) = Range(&#8220;B2:E3&#8221;)<br>N(2) = Range(&#8220;B5:E6&#8221;)<br>N(3) = Range(&#8220;B8:E9&#8221;)<br>N(4) = Range(&#8220;B11:E12&#8221;)<br>N(5) = Range(&#8220;B14:E15&#8221;)</p><p>Range(&#8220;G8:J9&#8221;) = N(<span class="bold-blue">Number</span>)</p><p>End Sub</p></blockquote>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="478" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-25-1024x478.png" alt="" class="wp-image-3362" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-25-1024x478.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-25-300x140.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-25-768x358.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-25.png 1099w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>N（4）の配列を貼り付けることができました。</p>



<p>　</p>



<p>では本題です。<br>複数の配列の中の位置・セルに入力・出力をしてみましょう。</p>



<p><strong><span class="marker-under">１つの配列だと「変数（行数,列数）」で</span></strong>したね。<br><strong><span class="marker-under">複数の配列の場合は「変数（<span class="bold-red">配列数</span>）（<span class="bold-blue">行数</span>,<span class="bold-green">列数</span>）」</span></strong>となります。</p>



<p>では実際にプログラムにて確認していきましょう。<br>先ほどの見本を活用し、N（<span class="bold-red">Number</span>）の<span class="bold-blue">1行目</span>の<span class="bold-green">３列目</span>に「456」を入力して<br>配列N（Number）をG8からJ9に貼り付けましょう。</p>



<p>今回はN(<span class="bold-red">3</span>)の配列を貼り付けたいと思います。</p>



<p>プログラムはこのようになります。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Sub 二次配列見本()</p><p>Dim N(5), Number As Long</p><p><span class="bold-red">Number</span> = <span class="bold-red">3</span> &#8216;表示したい配列番号を入力</p><p>N(1) = Range(&#8220;B2:E3&#8221;)<br>N(2) = Range(&#8220;B5:E6&#8221;)<br>N(3) = Range(&#8220;B8:E9&#8221;)<br>N(4) = Range(&#8220;B11:E12&#8221;)<br>N(5) = Range(&#8220;B14:E15&#8221;)</p><p>N(<span class="bold-red">Number</span>)(<span class="bold-blue">1</span>, <span class="bold-green">3</span>) = 456</p><p>Range(&#8220;G8:J9&#8221;) = N(Number)</p><p>End Sub</p></blockquote>



<p>実行した結果はこちらです。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="464" src="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-1024x464.png" alt="" class="wp-image-3363" srcset="https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-1024x464.png 1024w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-300x136.png 300w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26-768x348.png 768w, https://dokugakuexcel.com/wp-content/uploads/2022/07/image-26.png 1105w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>複数の配列内の指定した位置にも数値を格納できていますね。<br>もちろん計算させることも可能です。</p>



<h2 class="wp-block-heading"><span id="toc4">&#x2b1b;︎まとめ</span></h2>



<p>いかがだったでしょうか。<br>2次配列は複数のセルを格納できたり、配列の数も変えれたりと、とても便利です。</p>



<p>しかし初心者のかたは慣れるまで習得しにくく<br>できることも十分に理解するまで時間がかかるように思います。</p>



<p>是非配列の知識を身につけて<br>活用してみてください。</p>



<p>それでは次回の記事でお会いしましょう。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://dokugakuexcel.com/%e3%80%90%e3%83%9e%e3%82%af%e3%83%advba%e3%80%91%e8%a4%87%e6%95%b0%e3%81%ae2%e6%ac%a1%e9%85%8d%e5%88%97%e5%86%85%ef%bc%88%ef%bd%96ariant%e3%81%ae%e3%82%bb%e3%83%ab%e3%83%bb%e6%8c%87%e5%ae%9a%e4%bd%8d/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3356</post-id>	</item>
	</channel>
</rss>
