<?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: Conditional Import Text Files</title>
	<atom:link href="http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/</link>
	<description>Automation and VBA code for Microsoft® Excel and Outlook</description>
	<lastBuildDate>Fri, 03 Sep 2010 11:28:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/#comment-1515</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Fri, 14 Aug 2009 23:53:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=94#comment-1515</guid>
		<description>What&#039;s the error message?</description>
		<content:encoded><![CDATA[<p>What's the error message?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norhaya</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/#comment-1514</link>
		<dc:creator>Norhaya</dc:creator>
		<pubDate>Fri, 14 Aug 2009 04:26:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=94#comment-1514</guid>
		<description>I&#039;ve an error on this line

ReDim Preserve vArray(1 To lNextRow, 1 To 1))</description>
		<content:encoded><![CDATA[<p>I've an error on this line</p>
<p>ReDim Preserve vArray(1 To lNextRow, 1 To 1))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/#comment-1513</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Thu, 28 Aug 2008 03:06:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=94#comment-1513</guid>
		<description>JP - lNextRow updates here after the condition is tested and passes:

If (Left$(strLine, 3) = “ABC”) Then
lNextRow = 1 + lNextRow</description>
		<content:encoded><![CDATA[<p>JP &#8211; lNextRow updates here after the condition is tested and passes:</p>
<p>If (Left$(strLine, 3) = “ABC”) Then<br />
lNextRow = 1 + lNextRow</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/#comment-1512</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Wed, 27 Aug 2008 16:59:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=94#comment-1512</guid>
		<description>I like your code better, but where do you see lNextRow being incremented? It&#039;s based on &quot;WorksheetFunction.CountA(Range(&quot;A:A&quot;))&quot;, which wouldn&#039;t change if we didn&#039;t write the line to the worksheet.

--JP</description>
		<content:encoded><![CDATA[<p>I like your code better, but where do you see lNextRow being incremented? It's based on "WorksheetFunction.CountA(Range("A:A"))", which wouldn't change if we didn't write the line to the worksheet.</p>
<p>&#8211;JP</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Peltier</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2008/08/conditional-import-text-files/#comment-1511</link>
		<dc:creator>Jon Peltier</dc:creator>
		<pubDate>Tue, 26 Aug 2008 21:43:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=94#comment-1511</guid>
		<description>Instead of writing each line to the sheet as it is approved, write it to an array. Then at the end of the procedure, dump the array in one operation to the worksheet.

(Also, your original code increments lNextRow even if the input value for that row is not approved.)

Sub ConditionalImport()
Dim lNum As Long
Dim strLine As String
Dim lNextRow As Long
dim vArray() as Variant

Application.ScreenUpdating = False

&#039; get number of next free file
lNum = FreeFile

&#039; open text file for input, loop through each line,
&#039; only import rows we need

Open &quot;C:\testfile.txt&quot; For Input As #lNum
  lNextRow = 0
  ReDim vArray(1 To 1, 1 To 1)
  Do While Not EOF(lNum)
    Line Input #lNum, strLine

    If (Left$(strLine, 3) = &quot;ABC&quot;) Then
      lNextRow = 1 + lNextRow
      ReDim Preserve vArray(1 To lNextRow, 1 To 1))
      Cells(lNextRow + 1, 1).Value = strLine
    End If

  Loop

  ActiveSheet.Cells(1, 1).Resize(lNextRow).Value = vArray

Close lNum

Application.ScreenUpdating = True
End Sub</description>
		<content:encoded><![CDATA[<p>Instead of writing each line to the sheet as it is approved, write it to an array. Then at the end of the procedure, dump the array in one operation to the worksheet.</p>
<p>(Also, your original code increments lNextRow even if the input value for that row is not approved.)</p>
<p>Sub ConditionalImport()<br />
Dim lNum As Long<br />
Dim strLine As String<br />
Dim lNextRow As Long<br />
dim vArray() as Variant</p>
<p>Application.ScreenUpdating = False</p>
<p>' get number of next free file<br />
lNum = FreeFile</p>
<p>' open text file for input, loop through each line,<br />
' only import rows we need</p>
<p>Open "C:\testfile.txt" For Input As #lNum<br />
  lNextRow = 0<br />
  ReDim vArray(1 To 1, 1 To 1)<br />
  Do While Not EOF(lNum)<br />
    Line Input #lNum, strLine</p>
<p>    If (Left$(strLine, 3) = "ABC") Then<br />
      lNextRow = 1 + lNextRow<br />
      ReDim Preserve vArray(1 To lNextRow, 1 To 1))<br />
      Cells(lNextRow + 1, 1).Value = strLine<br />
    End If</p>
<p>  Loop</p>
<p>  ActiveSheet.Cells(1, 1).Resize(lNextRow).Value = vArray</p>
<p>Close lNum</p>
<p>Application.ScreenUpdating = True<br />
End Sub</p>
]]></content:encoded>
	</item>
</channel>
</rss>
