<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Multiple Substitute VBA</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 23:42:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: hans schraven</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42900</link>
		<dc:creator>hans schraven</dc:creator>
		<pubDate>Fri, 18 Dec 2009 22:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42900</guid>
		<description>&lt;p&gt;@Rick&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub tst4()&lt;br&gt;
&#160; Sheet1.Columns(1).SpecialCells(2).Copy Sheet1.Cells(1, 3)&lt;br&gt;
&#160; With Sheet1.Columns(3).SpecialCells(2)&lt;br&gt;
&#160; &#160; c0 = &quot; &quot; &amp; Join(WorksheetFunction.Transpose(.Value), &quot;&#124; &quot;)&lt;br&gt;
&#160; &#160; For Each cl In Sheet1.Columns(2).SpecialCells(2)&lt;br&gt;
&#160; &#160; &#160; c0 = Replace(c0, &quot; &quot; &amp; cl, &quot;&quot;)&lt;br&gt;
&#160; &#160; Next&lt;br&gt;
&#160; &#160; .Value = WorksheetFunction.Transpose(Split(Trim(c0), &quot;&#124; &quot;))&lt;br&gt;
&#160; End With&lt;br&gt;
End Sub&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;using 2 instead of xlcelltypeconstants makes the code code more robust, because it can also be run from other programs than Excel (for instance Word, Outlook, Access, etc.).&lt;br&gt;
Copying filled cells in column A to column C reduces the string c0 to its minimum.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Rick</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub tst4()<br />
&nbsp; Sheet1.Columns(1).SpecialCells(2).Copy Sheet1.Cells(1, 3)<br />
&nbsp; With Sheet1.Columns(3).SpecialCells(2)<br />
&nbsp; &nbsp; c0 = &#8221; &#8221; &amp; Join(WorksheetFunction.Transpose(.Value), &#8220;| &#8220;)<br />
&nbsp; &nbsp; For Each cl In Sheet1.Columns(2).SpecialCells(2)<br />
&nbsp; &nbsp; &nbsp; c0 = Replace(c0, &#8221; &#8221; &amp; cl, &#8220;&#8221;)<br />
&nbsp; &nbsp; Next<br />
&nbsp; &nbsp; .Value = WorksheetFunction.Transpose(Split(Trim(c0), &#8220;| &#8220;))<br />
&nbsp; End With<br />
End Sub</div>
</div>
<p>using 2 instead of xlcelltypeconstants makes the code code more robust, because it can also be run from other programs than Excel (for instance Word, Outlook, Access, etc.).<br />
Copying filled cells in column A to column C reduces the string c0 to its minimum.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vogus bum alias</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42762</link>
		<dc:creator>vogus bum alias</dc:creator>
		<pubDate>Fri, 11 Dec 2009 19:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42762</guid>
		<description>&lt;p&gt;I guess mine is a relatively long one. But it works.&lt;/p&gt;
&lt;p&gt;Function test(ByRef rng_lookup As Range, ByRef rng_find As Range) As String&lt;/p&gt;
&lt;p&gt;    Dim m As Variant, str_result As String, bln_matched As Boolean, int_count As Integer, arr_temp As Variant&lt;/p&gt;
&lt;p&gt;    arr_temp = Split(rng_lookup.Value)&lt;br&gt;
    str_result = rng_lookup.Value&lt;br&gt;
    Do&lt;br&gt;
        For Each m In rng_find.Value&lt;br&gt;
            If InStr(m, arr_temp(int_count)) &gt; 0 Then&lt;br&gt;
                &#039;=-= Example:&lt;br&gt;
                &#039;=-= m = South Dakota&lt;br&gt;
                &#039;=-= arr_temp(int_count) = South&lt;br&gt;
                If InStr(rng_lookup.Value, m) &gt; 0 Then&lt;br&gt;
                    &#039;=-= Example:&lt;br&gt;
                    &#039;=-= rng_lookup.value = Sofas South Dakota&lt;br&gt;
                    &#039;=-= m = South Dakota&lt;br&gt;
                    str_result = Replace(str_result, m, vbNullString)&lt;br&gt;
                    bln_matched = (InStr(rng_lookup.Value, m) - 1) + Len(m) = Len(rng_lookup.Value)&lt;br&gt;
                    Exit For&lt;br&gt;
                    End If&lt;br&gt;
                End If&lt;br&gt;
            Next &#039;=-= m&lt;br&gt;
        int_count = int_count + 1&lt;br&gt;
    Loop Until bln_matched Or int_count &gt; UBound(arr_temp) &#039;=-= will exit if the seach is done for all the chars or length of the lookup words reached the max after replacing the word&lt;/p&gt;
&lt;p&gt;    If str_result = vbNullString Then str_result = rng_lookup.Value&lt;br&gt;
    &#039;xx Debug.Print bln_matched &amp; &quot; -&gt; &quot; &amp; str_result&lt;br&gt;
    test = str_result&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I guess mine is a relatively long one. But it works.</p>
<p>Function test(ByRef rng_lookup As Range, ByRef rng_find As Range) As String</p>
<p>    Dim m As Variant, str_result As String, bln_matched As Boolean, int_count As Integer, arr_temp As Variant</p>
<p>    arr_temp = Split(rng_lookup.Value)<br />
    str_result = rng_lookup.Value<br />
    Do<br />
        For Each m In rng_find.Value<br />
            If InStr(m, arr_temp(int_count)) &gt; 0 Then<br />
                &#8216;=-= Example:<br />
                &#8216;=-= m = South Dakota<br />
                &#8216;=-= arr_temp(int_count) = South<br />
                If InStr(rng_lookup.Value, m) &gt; 0 Then<br />
                    &#8216;=-= Example:<br />
                    &#8216;=-= rng_lookup.value = Sofas South Dakota<br />
                    &#8216;=-= m = South Dakota<br />
                    str_result = Replace(str_result, m, vbNullString)<br />
                    bln_matched = (InStr(rng_lookup.Value, m) &#8211; 1) + Len(m) = Len(rng_lookup.Value)<br />
                    Exit For<br />
                    End If<br />
                End If<br />
            Next &#8216;=-= m<br />
        int_count = int_count + 1<br />
    Loop Until bln_matched Or int_count &gt; UBound(arr_temp) &#8216;=-= will exit if the seach is done for all the chars or length of the lookup words reached the max after replacing the word</p>
<p>    If str_result = vbNullString Then str_result = rng_lookup.Value<br />
    &#8216;xx Debug.Print bln_matched &amp; &#8221; -&gt; &#8221; &amp; str_result<br />
    test = str_result</p>
<p>End Function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42760</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Fri, 11 Dec 2009 17:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42760</guid>
		<description>&lt;p&gt;@hans... That looks good now, except for your not Dim&#039;ming your variables, that is [grin]. Your overall structure is similar to the code I posted (for example, your last line, except for the delimiter, looks a lot like the one I had to use in my code), but your &quot;set up&quot; for it is more compact. I especially like how you used SpecialCells function (although I would have used the predefined constant xlCellTypeConstants rather than the &quot;magic number&quot; 2 for its argument) even though using it does obfuscate the fact that the list of states is being iterated.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@hans&#8230; That looks good now, except for your not Dim&#8217;ming your variables, that is [grin]. Your overall structure is similar to the code I posted (for example, your last line, except for the delimiter, looks a lot like the one I had to use in my code), but your &#8220;set up&#8221; for it is more compact. I especially like how you used SpecialCells function (although I would have used the predefined constant xlCellTypeConstants rather than the &#8220;magic number&#8221; 2 for its argument) even though using it does obfuscate the fact that the list of states is being iterated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42759</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Fri, 11 Dec 2009 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42759</guid>
		<description>&lt;p&gt;@fzz.... Well, that&#039;s true, Transpose does do a &quot;behind the scenes&quot; loop, but that can also be said for Replace, InStr, Trim, Array, Split, and several other function calls as well, so I&#039;m not that sure we should be counting them as &quot;loops&quot; per se.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@fzz&#8230;. Well, that&#8217;s true, Transpose does do a &#8220;behind the scenes&#8221; loop, but that can also be said for Replace, InStr, Trim, Array, Split, and several other function calls as well, so I&#8217;m not that sure we should be counting them as &#8220;loops&#8221; per se.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hans schraven</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42758</link>
		<dc:creator>hans schraven</dc:creator>
		<pubDate>Fri, 11 Dec 2009 17:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42758</guid>
		<description>&lt;p&gt;Rick,&lt;/p&gt;
&lt;p&gt;I didn&#039;t see any cell in Dick&#039;s &#039;problem&#039; beginning with the name of a state.&lt;br&gt;
But nevertheless.&lt;br&gt;
And to prevent areas in column 1&lt;/p&gt;
&lt;div style=&quot;overflow: auto; white-space: nowrap;&quot; class=&quot;codecolorer-container text default&quot;&gt;&lt;div style=&quot;white-space: nowrap;&quot; class=&quot;text codecolorer&quot;&gt;Sub tst()&lt;br&gt;
c0 = Join(WorksheetFunction.Transpose(Sheets(1).usedrange.columns(1)), &quot;&#124;&quot;)&lt;br&gt;
For Each cl In Sheets(1).Columns(2).SpecialCells(2)&lt;br&gt;
c0 = Replace(c0, cl, &quot;&quot;)&lt;br&gt;
Next&lt;br&gt;
Sheets(1).usedrange.Columns(1).Offset(, 2) = WorksheetFunction.Transpose(Split(replace(replace(c0,&quot; &#124;&quot;,&quot;&#124;&quot;),&quot;&#124; &quot;,&quot;&#124;&quot;), &quot;&#124;&quot;))&lt;br&gt;
End Sub&lt;/div&gt;&lt;/div&gt;
</description>
		<content:encoded><![CDATA[<p>Rick,</p>
<p>I didn&#8217;t see any cell in Dick&#8217;s &#8216;problem&#8217; beginning with the name of a state.<br />
But nevertheless.<br />
And to prevent areas in column 1</p>
<div style="overflow: auto; white-space: nowrap;" class="codecolorer-container text default">
<div style="white-space: nowrap;" class="text codecolorer">Sub tst()<br />
c0 = Join(WorksheetFunction.Transpose(Sheets(1).usedrange.columns(1)), &#8220;|&#8221;)<br />
For Each cl In Sheets(1).Columns(2).SpecialCells(2)<br />
c0 = Replace(c0, cl, &#8220;&#8221;)<br />
Next<br />
Sheets(1).usedrange.Columns(1).Offset(, 2) = WorksheetFunction.Transpose(Split(replace(replace(c0,&#8221; |&#8221;,&#8221;|&#8221;),&#8221;| &#8220;,&#8221;|&#8221;), &#8220;|&#8221;))<br />
End Sub</div>
</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: fzz</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42757</link>
		<dc:creator>fzz</dc:creator>
		<pubDate>Fri, 11 Dec 2009 17:20:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42757</guid>
		<description>&lt;p&gt;@Rick - one explicit loop, but each Application.Transpose call is an implicit loop, so your code&#039;s runtime may reflect 3 loops rather than 1 or 2.&lt;/p&gt;
&lt;p&gt;@f - yes, you could use regular expressions, but the regex needed would be quite long. Something structured like&lt;/p&gt;
&lt;p&gt;(Alabama&#124;Alaska&#124;...&#124;Wyoming)&lt;/p&gt;
&lt;p&gt;would also address Rick&#039;s concern about replacing Virginia before West Virginia. Once again, regular expressions rule!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Rick &#8211; one explicit loop, but each Application.Transpose call is an implicit loop, so your code&#8217;s runtime may reflect 3 loops rather than 1 or 2.</p>
<p>@f &#8211; yes, you could use regular expressions, but the regex needed would be quite long. Something structured like</p>
<p>(Alabama|Alaska|&#8230;|Wyoming)</p>
<p>would also address Rick&#8217;s concern about replacing Virginia before West Virginia. Once again, regular expressions rule!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42756</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Fri, 11 Dec 2009 16:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42756</guid>
		<description>&lt;p&gt;hans... one other possible problem I see with your code... it will fail if there is one or more blank rows in between the data in Column A.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>hans&#8230; one other possible problem I see with your code&#8230; it will fail if there is one or more blank rows in between the data in Column A.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Rothstein (MVP - Excel)</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42755</link>
		<dc:creator>Rick Rothstein (MVP - Excel)</dc:creator>
		<pubDate>Fri, 11 Dec 2009 16:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42755</guid>
		<description>&lt;p&gt;hans... your code fails if the name of the state is the first word(s) in the text.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>hans&#8230; your code fails if the name of the state is the first word(s) in the text.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hans schraven</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42754</link>
		<dc:creator>hans schraven</dc:creator>
		<pubDate>Fri, 11 Dec 2009 16:21:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42754</guid>
		<description>&lt;p&gt;[vb]Sub tst()&lt;br&gt;
    c0 = Join(WorksheetFunction.Transpose(Sheets(1).Columns(1).SpecialCells(2)), &quot;&#124;&quot;)&lt;br&gt;
    For Each cl In Sheets(1).Columns(2).SpecialCells(2)&lt;br&gt;
       c0 = Replace(c0, &quot; &quot; &amp; cl, &quot;&quot;)&lt;br&gt;
    Next&lt;br&gt;
    Sheets(1).Columns(1).SpecialCells(2).Offset(, 2) = WorksheetFunction.Transpose(Split(c0, &quot;&#124;&quot;))&lt;br&gt;
End Sub[/vb]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[vb]Sub tst()<br />
    c0 = Join(WorksheetFunction.Transpose(Sheets(1).Columns(1).SpecialCells(2)), &#8220;|&#8221;)<br />
    For Each cl In Sheets(1).Columns(2).SpecialCells(2)<br />
       c0 = Replace(c0, &#8221; &#8221; &amp; cl, &#8220;&#8221;)<br />
    Next<br />
    Sheets(1).Columns(1).SpecialCells(2).Offset(, 2) = WorksheetFunction.Transpose(Split(c0, &#8220;|&#8221;))<br />
End Sub[/vb]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: f</title>
		<link>http://www.dailydoseofexcel.com/archives/2009/12/10/multiple-substitute-vba/#comment-42749</link>
		<dc:creator>f</dc:creator>
		<pubDate>Fri, 11 Dec 2009 14:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=3368#comment-42749</guid>
		<description>&lt;p&gt;Isnt this something you could use regex for?  Here is a solution to that find state codes (certainly a little easier) but you could look around for more.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.velocityreviews.com/forums/t293534-regular-expression-for-case-insensitive-usa-state-codes.html&quot; rel=&quot;nofollow&quot;&gt;http://www.velocityreviews.com/forums/t293534-regular-expression-for-case-insensitive-usa-state-codes.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regex would split the string automatically, regardless of what is around it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Isnt this something you could use regex for?  Here is a solution to that find state codes (certainly a little easier) but you could look around for more.</p>
<p><a href="http://www.velocityreviews.com/forums/t293534-regular-expression-for-case-insensitive-usa-state-codes.html" rel="nofollow">http://www.velocityreviews.com/forums/t293534-regular-expression-for-case-insensitive-usa-state-codes.html</a></p>
<p>Regex would split the string automatically, regardless of what is around it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

