<?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://lemon818.com/tag/%E3%83%97%E3%83%AD%E3%82%B7%E3%83%BC%E3%82%B8%E3%83%A3/feed/" rel="self" type="application/rss+xml" />
	<link>https://lemon818.com</link>
	<description>現役システムエンジニアが趣味でプログラミングする自由気ままなブログ</description>
	<lastBuildDate>Fri, 28 May 2021 12:03:37 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/>	<item>
		<title>【Excel vba】表のセル最終行・最終列番号の取得する処理・関数を紹介！コピペでOK！</title>
		<link>https://lemon818.com/excel-vba-last-row-col/</link>
		
		<dc:creator><![CDATA[Take]]></dc:creator>
		<pubDate>Sat, 10 Nov 2018 11:46:18 +0000</pubDate>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[vba]]></category>
		<category><![CDATA[プロシージャ]]></category>
		<category><![CDATA[マクロ]]></category>
		<category><![CDATA[最終列]]></category>
		<category><![CDATA[最終行]]></category>
		<category><![CDATA[関数]]></category>
		<guid isPermaLink="false">https://lemon818.com/?p=1020</guid>

					<description><![CDATA[Excel Vba で表の最終行する処理を知りたい！ &#160; このページでは Excel の表の最終行・最終列番号を取得する処理について Excel Vba の関数（プロシージャ）として簡単にまとめましたので記述し…]]></description>
										<content:encoded><![CDATA[<div class="sc_frame_wrap solid yellow">
<div class="sc_frame ">
<div class="sc_frame_text">
<p><strong><span style="color: #000000;">Excel Vba で表の最終行する処理を知りたい！</span></strong></p>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>このページでは Excel の表の最終行・最終列番号を取得する処理について</p>
<p>Excel Vba の関数（プロシージャ）として簡単にまとめましたので記述します。</p>
<p>&nbsp;</p>
<div class="voice clearfix left n_bottom">
<div class="icon">
<p><img decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2019/07/hukurou.jpg" /></p>
<div class="name"></div>
</div>
<div class="text sc_balloon left white">よく使う処理の前なのによく忘れるので備忘録に残しています！</div>
</div>
<p>&nbsp;</p>
<p>この処理はかなり簡単な関数（プロシージャ）としてまとめてます。</p>
<div class="sc_designlist ol square solid blue">
<ol>
<li>セル番号を指定（たとえば B2 という形式）</li>
<li>最終行・列を取得（B列の最終行・列をゲット！）</li>
</ol>
</div>
<p>&nbsp;</p>
<p>こんな感じで<span style="color: #3366ff;"><strong>すごく簡単な処理</strong></span>になっています。</p>
<p>また<strong><span style="background-color: #ffff00;">この処理はコピーすればすぐに実装できる</span></strong>ようにしています。</p>
<p>ですので、よければ必要な方はぜひコピペして使ってください。</p>
<p>&nbsp;</p>
<div class="sc_frame_wrap block blue">
<div class="sc_frame_title">この記事でわかること！</div>
<div class="sc_frame ">
<div class="sc_frame_text">
<div class="sc_designlist ol square solid blue">
<ol>
<li>表の最終行番号を取得する処理について</li>
<li>表の最終列番号を取得する処理について</li>
</ol>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
<h2><span style="font-family: helvetica, arial, sans-serif; font-size: 20px;">Excel の表の最終行番号を取得</span><span style="font-family: helvetica, arial, sans-serif; font-size: 20px;">する処理について</span></h2>
<p>Excel の表の最終行番号を取得する方法は２通りあります。</p>
<p>&nbsp;</p>
<div class="sc_designlist ol square solid blue">
<ol>
<li>セルの元々の位置から空白セルの位置まで下って移動</li>
<li>セルの一番下から空白セルの位置まで上って移動</li>
</ol>
</div>
<p>&nbsp;</p>
<p>「<span style="color: #ff0000;"><strong>は？どういうこと？？</strong></span>」と思われた方もいるかもしれません。</p>
<p>これがどういうことなのかわかりやすく説明します。</p>
<p>&nbsp;</p>
<h3>セルの元々の位置から空白セルの位置まで下って移動</h3>
<p>まずは最終行取得のために「セルの元々の位置から空白セルの位置まで下って移動」する方法についてです。</p>
<p>&nbsp;</p>
<p>まずはこんな感じの１~５まで含まれる１列の表があるとします。</p>
<p>ここの一番上のセル番号（B2）を選択します。</p>
<p>&nbsp;</p>
<p><img fetchpriority="high" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-1.png" alt="" width="346" height="237" class="aligncenter size-full wp-image-5600" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-1.png 346w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-1-300x205.png 300w" sizes="(max-width: 346px) 100vw, 346px" /></p>
<p>&nbsp;</p>
<p>そしてキーボードの「↓」キーを入力すれば表の一番下のセルに移動できます。</p>
<p>&nbsp;</p>
<p><img decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-2.png" alt="" width="352" height="249" class="aligncenter size-full wp-image-5601" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-2.png 352w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-2-300x212.png 300w" sizes="(max-width: 352px) 100vw, 352px" /></p>
<p>&nbsp;</p>
<p>いわばこの処理を Excel VBAで実現すればOKっていうことです。</p>
<p>実際の Excel Vba での最終行のセル番号を取得する処理は下記になります。</p><pre class="crayon-plain-tag">Sub test()

    Debug.Print getLastRow("B2")
    
End Sub

Function getLastRow(nowCell As String)
    
    getLastRow = Range(nowCell).End(xlDown).row

End Function</pre><p>
&nbsp;</p>
<p>上記は B2セル（表の一番上）から End(xlDown) と下っていくこと処理です。</p>
<p>今回はこの処理を getLastRow プロシージャとしてまとめました。</p>
<p>この関数（プロシージャ）の引数と戻り値は下記になります。</p>
<p>&nbsp;</p>
<table style="height: 116px; width: 78.0905%; border-collapse: collapse;" border="1" align="center">
<tbody>
<tr style="height: 24px; background-color: #0099e6;">
<td style="width: 24.8693%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>項目名</strong></span></td>
<td style="width: 46.4305%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>値</strong></span></td>
<td style="width: 28.7001%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>説明</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 24.8693%; height: 23px; background-color: #fffcd9;"><span style="font-family: helvetica, arial, sans-serif;"><strong>プロシージャ名</strong></span></td>
<td style="width: 46.4305%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>getLastRow</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>最終行番号取得</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 24.8693%; height: 23px; background-color: #fffcd9;"><span style="font-family: helvetica, arial, sans-serif;"><strong>戻り値</strong></span></td>
<td style="width: 46.4305%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>指定したシート名の列の最終行番号</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>-</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 24.8693%; height: 23px; background-color: #fffcd9;"><span style="font-family: helvetica, arial, sans-serif;"><strong>第１引数</strong></span></td>
<td style="width: 46.4305%; height: 23px;"><strong>nowCell</strong></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>セル番号（A1、B2）等</strong></span></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h3>セルの一番下から空白セルの位置まで上って移動</h3>
<p>次に「セルの一番下から空白セルの位置まで上って移動」する方法についてです。</p>
<p>&nbsp;</p>
<p>先程と同じようにこんな感じの１~５まで含まれる１列の表があるとします。</p>
<p>&nbsp;</p>
<p><img fetchpriority="high" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-1.png" alt="" width="346" height="237" class="aligncenter size-full wp-image-5600" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-1.png 346w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-1-300x205.png 300w" sizes="(max-width: 346px) 100vw, 346px" /></p>
<p>&nbsp;</p>
<p>これと同じ列の一番下のセルを選択します。</p>
<p>&nbsp;</p>
<p><img decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-3.png" alt="" width="470" height="177" class="aligncenter size-full wp-image-5603" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-3.png 470w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-3-300x113.png 300w" sizes="(max-width: 470px) 100vw, 470px" /></p>
<p>&nbsp;</p>
<p>そしてキーボードの「↑」キーを入力すれば<strong>表の</strong>一番下のセルに移動できます。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-4.png" alt="" width="260" height="306" class="aligncenter size-full wp-image-5602" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-4.png 260w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-4-255x300.png 255w" sizes="auto, (max-width: 260px) 100vw, 260px" /></p>
<p>&nbsp;</p>
<p>この処理を Excel VBAで実現すればOKっていうことです。</p>
<p>実際の Excel Vba での最終行のセル番号を取得する処理は下記になります。</p><pre class="crayon-plain-tag">Sub test() 

　　　Debug.Print getLastRow2("B2") 

End Sub

Function getLastRow2(row As String)

    getMaxRow = Cells(Rows.Count, Range(nowCell).Column).End(xlUp).row

End Function</pre><p>
&nbsp;</p>
<p>先程よりは少しややこしいです。</p>
<p>処理について順に説明します（例として B2セルの最終行を取得する場合を説明します）。</p>
<div class="sc_designlist ol square solid blue">
<ol>
<li>B2 セルから B2の列番号を取得を数字として取得します（たとえば B 列ならば「2」となります）。</li>
<li>次に Excel の最大行数 Rows.Count を取得し、これらを組み合わせてB列の最終セル番号（Cells(Rows.Count, Range(nowCell).Column)）とを取得します。</li>
<li>最後にB列の最終セル番号をEnd(xlUp) と上っていく処理にすればOKです。</li>
</ol>
</div>
<p>&nbsp;</p>
<p>今回はこの処理を getLastRow2 プロシージャとしてまとめました。</p>
<p>この関数（プロシージャ）の引数と戻り値は下記になります。</p>
<p>&nbsp;</p>
<table style="height: 116px; width: 78.0905%; border-collapse: collapse;" border="1" align="center">
<tbody>
<tr style="height: 24px; background-color: #0099e6;">
<td style="width: 33.3333%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>項目名</strong></span></td>
<td style="width: 37.9665%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>値</strong></span></td>
<td style="width: 28.7001%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>説明</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 33.3333%; height: 23px; background-color: #fffcd9;"><span style="font-family: helvetica, arial, sans-serif;"><strong>プロシージャ名</strong></span></td>
<td style="width: 37.9665%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>getLastRow2</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>最終行番号取得</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 33.3333%; height: 23px; background-color: #fffcd9;"><span style="font-family: helvetica, arial, sans-serif;"><strong>戻り値</strong></span></td>
<td style="width: 37.9665%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>指定したシート名の列の最終行番号</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>-</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 33.3333%; height: 23px; background-color: #fffcd9;"><span style="font-family: helvetica, arial, sans-serif;"><strong>第１引数</strong></span></td>
<td style="width: 37.9665%; height: 23px;"><strong>nowCell</strong></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>セル番号（A1、B2）等</strong></span></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h3>二つの処理の違いについて</h3>
<p>「<span style="color: #ff0000;"><strong>これ結局何が違うの？</strong></span>」ってなると思います。</p>
<p>これらの違いは Excel の行の中に<strong><span style="color: #3366ff;">空白があるかどうか</span></strong>であり、</p>
<p>空白があると最終行の値が変わってきます。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-5.png" alt="" width="508" height="376" class="aligncenter wp-image-5604" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-5.png 484w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-row-5-300x222.png 300w" sizes="auto, (max-width: 508px) 100vw, 508px" /></p>
<p>&nbsp;</p>
<p>例えば表の上から列番号を確認するとExcelの処理では<strong>空白セル直前のセル行番号</strong>になりますが、一番下から確認すると<strong>一番下のセル行番号</strong>になります。</p>
<p>&nbsp;</p>
<p>これらのように違いがあるため、使い分けする必要があります。</p>
<p>&nbsp;</p>
<div class="sc_frame_wrap block orange">
<div class="sc_frame_title">ポイント！</div>
<div class="sc_frame ">
<div class="sc_frame_text">Excel 行の間に<span style="color: #3366ff;"><strong>空白セルがあるかどうか</strong></span>で取得できる値が変わる！</div>
</div>
</div>
<p>&nbsp;</p>
<h2><span style="font-family: helvetica, arial, sans-serif; font-size: 20px;">Excel の</span><span style="font-family: helvetica, arial, sans-serif; font-size: 20px;">表の最終列番号を取得する処理について</span></h2>
<p>次にExcel の表の最終列番号を取得する方法は２通りあります。</p>
<p>これは前章で説明した「最終行番号取得のノウハウ」と特に変わりありません。</p>
<p>&nbsp;</p>
<div class="sc_designlist ol square solid blue">
<ol>
<li>セルの元々の位置から空白セルの位置まで右に移動して移動</li>
<li>セルの一番右から空白セルの位置まで右に移動</li>
</ol>
</div>
<p>&nbsp;</p>
<p>こちらも「<span style="color: #ff0000;"><strong>は？どういうこと？？</strong></span>」と思われた方もいるかもしれません。</p>
<p>これがどういうことなのかわかりやすく説明します。</p>
<p>&nbsp;</p>
<h3>セルの元々の位置から空白セルの位置まで右に移動して移動</h3>
<p>まずは「セルの元々の位置から空白セルの位置まで右に移動して移動」について説明します。</p>
<p>こんな感じの１~５まで含まれる１行の表があるとします。</p>
<p>ここの一番左のセル番号（B2）を選択します。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-1.png" alt="" width="538" height="156" class="aligncenter size-full wp-image-5607" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-1.png 538w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-1-300x87.png 300w" sizes="auto, (max-width: 538px) 100vw, 538px" /></p>
<p>&nbsp;</p>
<p>そしてキーボードの「→」キーを入力すれば表の一番右のセルに移動できます。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-2.png" alt="" width="552" height="141" class="aligncenter size-full wp-image-5608" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-2.png 552w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-2-300x77.png 300w" sizes="auto, (max-width: 552px) 100vw, 552px" /></p>
<p>&nbsp;</p>
<p>この処理を Excel VBAで実現すればOKっていうことです。</p>
<p>実際の Excel Vba での最終列のセル番号を取得する処理は下記になります。</p><pre class="crayon-plain-tag">Sub test() 

    Debug.Print getLastCol("B2") 

End Sub

Function getLastCol(nowCell As String)

    getMaxCol = Range(nowCell).End(xlToRight).Column

End Function</pre><p>
&nbsp;</p>
<p>上記は B2セル（表の一番左）から End(xlToRight) と右にいくこと処理です。</p>
<p>今回はこの処理を getLastCol プロシージャとしてまとめました。</p>
<p>この関数（プロシージャ）の引数と戻り値は下記になります。</p>
<p>&nbsp;</p>
<table style="height: 116px; width: 78.0905%; border-collapse: collapse;" border="1" align="center">
<tbody>
<tr style="height: 24px; background-color: #0099e6;">
<td style="width: 33.3333%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>項目名</strong></span></td>
<td style="width: 37.9665%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>値</strong></span></td>
<td style="width: 28.7001%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>説明</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 33.3333%; height: 23px; background-color: #fcfce6;"><span style="font-family: helvetica, arial, sans-serif; color: #000000;"><strong>プロシージャ名</strong></span></td>
<td style="width: 37.9665%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>getLastCol</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>最終列番号取得</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 33.3333%; height: 23px; background-color: #fcfce6;"><span style="font-family: helvetica, arial, sans-serif; color: #000000;"><strong>戻り値</strong></span></td>
<td style="width: 37.9665%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>指定したシート名の列の最終列番号</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>-</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 33.3333%; height: 23px; background-color: #fcfce6;"><span style="font-family: helvetica, arial, sans-serif; color: #000000;"><strong>第１引数</strong></span></td>
<td style="width: 37.9665%; height: 23px;"><strong>nowCell </strong></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>セル番号（A1、B2）等</strong></span></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h3>セルの一番右から空白セルの位置まで右に移動</h3>
<p>まずは「セルの一番右から空白セルの位置まで右に移動」について説明します。</p>
<p>まずはこんな感じの１~５まで含まれる１行の表があるとします。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-1.png" alt="" width="538" height="156" class="aligncenter size-full wp-image-5607" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-1.png 538w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-1-300x87.png 300w" sizes="auto, (max-width: 538px) 100vw, 538px" /></p>
<p>&nbsp;</p>
<p>ここで B列の最終行を選択します。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-3.png" alt="" width="382" height="187" class="aligncenter size-full wp-image-5609" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-3.png 382w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-3-300x147.png 300w" sizes="auto, (max-width: 382px) 100vw, 382px" /></p>
<p>&nbsp;</p>
<p>そしてキーボードの「←」キーを入力すれば表の一番右のセルに移動できます。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-4.png" alt="" width="541" height="134" class="aligncenter wp-image-5610" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-4.png 696w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-4-300x74.png 300w" sizes="auto, (max-width: 541px) 100vw, 541px" /></p>
<p>&nbsp;</p>
<p>この処理を Excel VBAで実現すればOKっていうことです。</p>
<p>実際の Excel Vba での最終列のセル番号を取得する処理は下記になります。</p>
<p>最終行のセル番号は下記になります。</p><pre class="crayon-plain-tag">Sub test() 

    Debug.Print getLastCol2("B2") 

End Sub

Function getLastCol2(nowCell As String)

    getLastCol2 = Cells(Range(nowCell).row, Columns.Count).End(xlToLeft).Column

End Function</pre><p>
&nbsp;</p>
<p>処理について順に説明します（例として B2セルの最終列を取得する場合を説明します）。</p>
<div class="sc_designlist ol square solid blue">
<ol>
<li>B2 セルから B2の行番号を取得を数字として取得します（たとえば B 列ならば「2」となります）。</li>
<li>次に Excel の最大列数 Columns.Count を取得し、これらを組み合わせてB列の最終セル番号 Cells(Range(nowCell).row, Columns.Count) とを取得します。</li>
<li>最後にB列の最終セル番号をEnd(xlToLeft) と右にいく処理にすればOKです。</li>
</ol>
</div>
<p>&nbsp;</p>
<p>この関数（プロシージャ）の引数と戻り値は下記になります。</p>
<p>&nbsp;</p>
<table style="height: 116px; width: 78.0905%; border-collapse: collapse;" border="1" align="center">
<tbody>
<tr style="height: 24px; background-color: #0099e6;">
<td style="width: 25.9665%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>項目名</strong></span></td>
<td style="width: 45.3333%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>値</strong></span></td>
<td style="width: 28.7001%; height: 24px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>説明</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 25.9665%; height: 23px; background-color: #fcfce6;"><span style="font-family: helvetica, arial, sans-serif; color: #000000;"><strong>プロシージャ名</strong></span></td>
<td style="width: 45.3333%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>getLastCol2</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>最終列番号取得</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 25.9665%; height: 23px; background-color: #fcfce6;"><span style="font-family: helvetica, arial, sans-serif; color: #000000;"><strong>戻り値</strong></span></td>
<td style="width: 45.3333%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>指定したシート名の列の最終列番号</strong></span></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>-</strong></span></td>
</tr>
<tr style="height: 23px;">
<td style="width: 25.9665%; height: 23px; background-color: #fcfce6;"><span style="font-family: helvetica, arial, sans-serif; color: #000000;"><strong>第1引数</strong></span></td>
<td style="width: 45.3333%; height: 23px;"><strong>nowCell </strong></td>
<td style="width: 28.7001%; height: 23px;"><span style="font-family: helvetica, arial, sans-serif;"><strong>セル番号（A1、B2）等</strong></span></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h3>二つの処理の違いについて</h3>
<p>「<span style="color: #ff0000;"><strong>これ結局何が違うの？</strong></span>」ってなると思います。</p>
<p>これらの違いは Excel の列の中に<strong><span style="color: #3366ff;">空白があるかどうか</span></strong>であり、</p>
<p>空白があると最終列の値が変わってきます。</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-5.png" alt="" width="743" height="239" class="aligncenter size-full wp-image-5611" srcset="https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-5.png 743w, https://lemon818.com/wp/wp-content/uploads/2018/11/excel-last-col-5-300x97.png 300w" sizes="auto, (max-width: 743px) 100vw, 743px" /></p>
<p>&nbsp;</p>
<p>例えば表の上から列番号を確認するとExcelの処理では<strong>空白セル直前のセル行番号</strong>になりますが、一番下から確認すると<strong>一番左のセル行番号</strong>になります。</p>
<p>これらのように違いがあるため、使い分けする必要があります。</p>
<p>&nbsp;</p>
<div class="sc_frame_wrap block orange">
<div class="sc_frame_title">ポイント！</div>
<div class="sc_frame ">
<div class="sc_frame_text">Excel 列の間に<span style="color: #3366ff;"><strong>空白セルがあるかどうか</strong></span>で取得できる値が変わる！</div>
</div>
</div>
<p>&nbsp;</p>
<h2>最後に</h2>
<p>いかがでしたでしょうか？</p>
<p>今回はこんなことを紹介しました！</p>
<div class="sc_designlist ol square solid blue">
<ol>
<li>Excel の表の最終行番号を取得する処理について</li>
<li>Excel の表の最終列番号を取得する処理について</li>
</ol>
</div>
<p>&nbsp;</p>
<p>この記事が開発のお役に立てれば幸いです。</p>
<p>&nbsp;</p>
<p>ではでは。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
