<?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>Blog de Philippe Vialatte &#187; Excel</title>
	<atom:link href="https://blog.developpez.com/philippe/pcategory/excel/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/philippe</link>
	<description></description>
	<lastBuildDate>Fri, 03 Jan 2014 15:12:09 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Excel : quelques fonctions sympas sur les tableaux</title>
		<link>https://blog.developpez.com/philippe/p12250/divers/excel-quelques-fonctions-sympas-sur-les-tableaux</link>
		<comments>https://blog.developpez.com/philippe/p12250/divers/excel-quelques-fonctions-sympas-sur-les-tableaux#comments</comments>
		<pubDate>Wed, 25 Sep 2013 11:45:00 +0000</pubDate>
		<dc:creator><![CDATA[Philippe Vialatte]]></dc:creator>
				<category><![CDATA[Divers]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[tableaux]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philippe/?p=240</guid>
		<description><![CDATA[Dans la série “Excel et moi, je t’aime, moi non plus”, le sujet du jour concerne la manipulation des tableaux. On a tellement l’habitude, dans un langage de programmation moderne, de manipuler des tableaux d’objets, que, avec Excel, on s’attendrait a un comportement un peu civilisé. Du type : exposer une possibilité simple d’itérer sur les lignes d’un tableau, permettre de vider un tableau, ou de créer un tableau de manière propre …bah en fait, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Dans la série “Excel et moi, je t’aime, moi non plus”, le sujet du jour concerne la manipulation des tableaux.</p>
<p>On a tellement l’habitude, dans un langage de programmation moderne, de manipuler des tableaux d’objets, que, avec Excel, on s’attendrait a un comportement un peu civilisé.</p>
<p>Du type : exposer une possibilité simple d’itérer sur les lignes d’un tableau, permettre de vider un tableau, ou de créer un tableau de manière propre</p>
<p>…bah en fait, non…</p>
<p>Du coup, comme j’en avais besoin, 3 petites fonction qui font juste ça :</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">Sub</span> ParcourirTable(sheet <span style="color: #0000ff">As</span> Worksheet,nomTable <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>)</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    sheet.<span style="color: #0000ff">Select</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">Dim</span> tbl <span style="color: #0000ff">As</span> ListObject</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">Set</span> tbl = ActiveSheet.ListObjects(nomTable)</pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">Dim</span> row <span style="color: #0000ff">As</span> Range</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">Dim</span> cell <span style="color: #0000ff">As</span> Range</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> row <span style="color: #0000ff">In</span> tbl.DataBodyRange.Rows</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">For</span> <span style="color: #0000ff">Each</span> cell <span style="color: #0000ff">In</span> row.Cells</pre>
<p><!--CRLF--></p>
<pre>            Debug.Print cell.Value</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">Next</span></pre>
<p><!--CRLF--></p>
<pre>        Debug.Print <span style="color: #006080">&quot;---&quot;</span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">Next</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">Sub</span> EffacerContenuTable(sheet <span style="color: #0000ff">As</span> Worksheet, nomTable <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>)</pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre>    sheet.<span style="color: #0000ff">Select</span></pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">With</span> ActiveSheet.ListObjects(nomTable )</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">If</span> <span style="color: #0000ff">Not</span> .DataBodyRange <span style="color: #0000ff">Is</span> <span style="color: #0000ff">Nothing</span> <span style="color: #0000ff">Then</span></pre>
<p><!--CRLF--></p>
<pre>            .DataBodyRange.ClearContents</pre>
<p><!--CRLF--></p>
<pre>            .DataBodyRange.Delete</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span></pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">End</span> <span style="color: #0000ff">With</span></pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">Sub</span> CreerTable(sheet <span style="color: #0000ff">As</span> Worksheet, nom <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>, adresse <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span>)</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    sheet.ListObjects.Add(xlSrcRange, range(adresse), , xlYes).Name = nom</pre>
<p><!--CRLF--></p>
<pre>    </pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">End</span> <span style="color: #0000ff">Sub</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></div>
</div>
<div id="codeSnippetWrapper"></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excel : convertir le num&#233;ro d&#8217;une colonne en lettre</title>
		<link>https://blog.developpez.com/philippe/p12187/excel/excel-convertir-le-numero-dune-colonne-en-lettre</link>
		<comments>https://blog.developpez.com/philippe/p12187/excel/excel-convertir-le-numero-dune-colonne-en-lettre#comments</comments>
		<pubDate>Thu, 22 Aug 2013 08:40:41 +0000</pubDate>
		<dc:creator><![CDATA[Philippe Vialatte]]></dc:creator>
				<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/philippe/?p=229</guid>
		<description><![CDATA[Un petit problème sur&#8230;a peu près tous les dev en vba, et qui est souvent posé sur divers forum Excel, est la conversion du numéro d&#8217;une colonne en texte. Dans mes recherches, je suis tombé sur: - des formules qui marchaient bien&#8230;tant qu&#8217;on avait des numéros inférieurs a 78 - des formules qui marchaient bien&#8230;tant qu&#8217;on n&#8217;était pas sur un multiple de 26 - des formules qui marchaient&#8230;pas du tout Pour ceux que cela peut [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Un petit problème sur&#8230;a peu près tous les dev en vba, et qui est souvent posé sur divers forum Excel, est la conversion du numéro d&rsquo;une colonne en texte.</p>
<p>Dans mes recherches, je suis tombé sur:    <br />- des formules qui marchaient bien&#8230;tant qu&rsquo;on avait des numéros inférieurs a 78     <br />- des formules qui marchaient bien&#8230;tant qu&rsquo;on n&rsquo;était pas sur un multiple de 26     <br />- des formules qui marchaient&#8230;pas du tout</p>
<p>Pour ceux que cela peut intéresser (et pour moi quand j&rsquo;aurait oublié <img src="https://blog.developpez.com/philippe/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /> ), les deux seules méthodes qui marchent de façon satisfaisantes sont les suivantes :</p>
<p><span id="more-229"></span>
<p>En VBA: </p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Function</span> ColID2Ltr(columnId <span style="color: #0000ff">As</span> <span style="color: #0000ff">Integer</span>) <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">If</span> columnId &gt; 26 <span style="color: #0000ff">Then</span></pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #008000">' si la colonne est supérieur a 26, il faut la représenter sur au moins 2 caractères</span></pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #008000">' on récupère la partie la plus a droite du nombre a décomposer, et on appelle de façon récursive ColID2Ltr</span></pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">Dim</span> partieGauche <span style="color: #0000ff">As</span> <span style="color: #0000ff">Integer</span>, partieDroite <span style="color: #0000ff">As</span> <span style="color: #0000ff">Integer</span></pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">If</span> (columnId <span style="color: #0000ff">Mod</span> 26 0) <span style="color: #0000ff">Then</span></pre>
<p><!--CRLF--></p>
<pre>            partieDroite = columnId <span style="color: #0000ff">Mod</span> 26</pre>
<p><!--CRLF--></p>
<pre>            partieGauche = (columnId - partieDroite) / 26</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">Else</span></pre>
<p><!--CRLF--></p>
<pre>            partieDroite = 26</pre>
<p><!--CRLF--></p>
<pre>            partieGauche = (columnId / 26) - 1</pre>
<p><!--CRLF--></p>
<pre>        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span></pre>
<p><!--CRLF--></p>
<pre>        ColID2Ltr = ColID2Ltr(partieGauche) + NumToChar(partieDroite)</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">Else</span></pre>
<p><!--CRLF--></p>
<pre>        ColID2Ltr = NumToChar(columnId)</pre>
<p><!--CRLF--></p>
<pre>    <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">End</span> <span style="color: #0000ff">Function</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">Public</span> <span style="color: #0000ff">Function</span> NumToChar(id <span style="color: #0000ff">As</span> <span style="color: #0000ff">Integer</span>) <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span></pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre>    NumToChar = Chr(id + 64)</pre>
<p><!--CRLF--></p>
<pre>&#160;</pre>
<p><!--CRLF--></p>
<pre><span style="color: #0000ff">End</span> <span style="color: #0000ff">Function</span></pre>
<p><!--CRLF--></div>
</div>
<p>Si on ne veut pas utiliser de VBA, le plus simple est d&rsquo;utiliser (si le nombre que l&rsquo;on veut convertir est dans la colonne A1 :<br />
  </p>
<div id="codeSnippetWrapper">
<div id="codeSnippet">
<pre>=SUBSTITUE(ADRESSE(1;A1;4);<span style="color: #006080">&quot;1&quot;</span>;<span style="color: #006080">&quot;&quot;</span>)</pre>
<p><!--CRLF--></div>
</p></div>
</p>
<p><a href="http://blog.developpez.com/philippe/files/2013/08/ColID2Ltr.png"><img class="alignnone size-full wp-image-230" alt="ColID2Ltr" src="http://blog.developpez.com/philippe/files/2013/08/ColID2Ltr.png" width="255" height="543" /></a></p>
<p>Attention, la formule basée sur SUBSTITUE a une limitation, a savoir qu&rsquo;elle ne peut pas calculer au-delà de la capacité du classeur.</p>
<p>Par exemple, dans un classeur au format xls, la valeur maximale gérée par cette formule sera 256 (IV), la ou, dans un classeur xlsx, avec Excel 2010, ce sera 16384.</p>
<p>Par contre, pour la fonction VBA&#8230;la limite devient 32 767, ou AVLG (on pourrait aller plus loin avec des long, mais je ne vois pas l&rsquo;intérêt <img src="https://blog.developpez.com/philippe/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /> )</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
