title: Excel VBA If 1 Row Don't Autofill Almost works
body: <p>New to forum and very new to VBA.  I'm trying to consolidate data off hundreds of forms I get every month.  I have to grab a few extra fields off the forms (names, dates, stores) and fill down alongside the other columns. I've run into the error of when there is only one row of data and can't autofill.  I've tried to work around this with an IF, Then, Else.  What happens is after it hits a file that has that one row, it will not do the autofill on any subsequent files with more than one.  It almost works.</p>
  <p>Code:</p>
  <pre><code>Sub test()
  Dim FolderPath As String
  Dim FileName As String
  Dim wb As Excel.Workbook
  Dim Erow
  Application.ScreenUpdating = 0
  Application.DisplayAlerts = 0
  
  FolderPath = &quot;C:\Users\Test\&quot;
  FileName = Dir(FolderPath &amp; &quot;*.xlsx&quot;)
  
  
      Do While FileName &lt;&gt; &quot;&quot;
      
      Workbooks.Open (FolderPath &amp; FileName)
      Range(&quot;B10&quot;).Select
      Selection.Copy
      Range(&quot;K17&quot;).Select
      ActiveSheet.Paste
      Range(&quot;J9&quot;).Select
      Application.CutCopyMode = False
      Selection.Copy
      Range(&quot;L17&quot;).Select
      ActiveSheet.Paste
      Range(&quot;J11&quot;).Select
      Selection.Copy
      Range(&quot;M17&quot;).Select
      ActiveSheet.Paste
  
      Dim lastRow As Long
      If lastRow &gt; 17 Then
      lastRow = Range(&quot;D&quot; &amp; Rows.Count).End(xlUp).Row
      Range(&quot;K17&quot;).AutoFill Destination:=Range(&quot;K17:K&quot; &amp; lastRow), 
      Type:=xlFillCopy
      lastRow = Range(&quot;D&quot; &amp; Rows.Count).End(xlUp).Row
      Range(&quot;L17&quot;).AutoFill Destination:=Range(&quot;L17:L&quot; &amp; lastRow), 
      Type:=xlFillCopy
      lastRow = Range(&quot;D&quot; &amp; Rows.Count).End(xlUp).Row
      Range(&quot;M17&quot;).AutoFill Destination:=Range(&quot;M17:M&quot; &amp; lastRow), 
      Type:=xlFillCopy
      Else
      ActiveWorkbook.Save
      Range(&quot;A17:M200&quot;).Copy
      ActiveWorkbook.Close
      End If
  
  Erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
  ActiveSheet.Paste Destination:=Worksheets(&quot;Sheet1&quot;).Range(Cells(Erow, 1), Cells(Erow, 13))
  
  FileName = Dir
  
  Loop
  End Sub
  </code></pre>
  <p>Here is a screenshot of what happens after the &quot;one row&quot; file.</p>
  <h3>Error After One Row, Auto Fill stops</h3>
  <p><img src="https://i.stack.imgur.com/2soeh.png" alt="Error After One Row, Auto Fill stops" /></p>