title: VBA, data is not populating in new columns. Possible issue with Advanced Filter
body: <p>We have added 5 new columns to three sheets in a workbook.  The first sheet is like a staging table that then populates the other two.  The problem is the new columns are not being populated with the data in the two final sheets.  The data is visible in the intial sheet.  I think it may be an issue with the Advanced Filter but im not sure.  Any help would be appreciated.</p>
  <pre class="lang-vb prettyprint-override"><code>Public Sub RunExtract()
      
      Dim strExtractYear As String
      Dim strExtractMonth As String
      Dim strOutputFolder As String
      
      Application.ScreenUpdating = False
      
      'grab the control variable values
      strExtractYear = Range(&quot;Extract_Year&quot;).Value
      strExtractMonth = Range(&quot;Extract_Month&quot;).Value
      strOutputFolder = Range(&quot;Output_Folder&quot;).Value
      
      
      'pull the data
      Application.StatusBar = &quot;Pulling data...&quot;
      Call PullData(strExtractYear, strExtractMonth)
      
      
      'filter and output the results
      Application.StatusBar = &quot;Extracting 310 summary data...&quot;
      Range(&quot;SummaryFilter.Criteria&quot;).Cells(2, 2).Formula = &quot;=&quot;&quot;=310&quot;&quot;&quot;
      Call FilterData(Range(&quot;SalesExtract.Table&quot;), Range(&quot;SummaryFilter.Criteria&quot;), Range(&quot;SummaryFilter.Header&quot;), &quot;SummaryFilter.Table&quot;)
      Call OutputResults(&quot;SUMMARY&quot;, &quot;310&quot;, strOutputFolder)
      
      Application.StatusBar = &quot;Extracting 430 summary data...&quot;
      Range(&quot;SummaryFilter.Criteria&quot;).Cells(2, 2).Formula = &quot;=&quot;&quot;=430&quot;&quot;&quot;
      Call FilterData(Range(&quot;SalesExtract.Table&quot;), Range(&quot;SummaryFilter.Criteria&quot;), Range(&quot;SummaryFilter.Header&quot;), &quot;SummaryFilter.Table&quot;)
      Call OutputResults(&quot;SUMMARY&quot;, &quot;430&quot;, strOutputFolder)
      
      Application.StatusBar = &quot;Extracting 310 detail data...&quot;
      Range(&quot;DetailFilter.Criteria&quot;).Cells(2, 2).Formula = &quot;=&quot;&quot;=310&quot;&quot;&quot;
      Call FilterData(Range(&quot;SalesExtract.Table&quot;), Range(&quot;DetailFilter.Criteria&quot;), Range(&quot;DetailFilter.Header&quot;), &quot;DetailFilter.Table&quot;)
      Call OutputResults(&quot;DETAIL&quot;, &quot;310&quot;, strOutputFolder)
      
      Application.StatusBar = &quot;Extracting 430 detail data...&quot;
      Range(&quot;DetailFilter.Criteria&quot;).Cells(2, 2).Formula = &quot;=&quot;&quot;=430&quot;&quot;&quot;
      Call FilterData(Range(&quot;SalesExtract.Table&quot;), Range(&quot;DetailFilter.Criteria&quot;), Range(&quot;DetailFilter.Header&quot;), &quot;DetailFilter.Table&quot;)
      Call OutputResults(&quot;DETAIL&quot;, &quot;430&quot;, strOutputFolder)
      
      Call CleanUpThisWorkbook
      
      Application.StatusBar = &quot;Done&quot;
      
      Application.CutCopyMode = False
      Application.ScreenUpdating = True
      
  End Sub
  
  Public Sub PullData(ExtractYear As String, ExtractMonth As String)
  
      Dim conn As ADODB.Connection
      Dim cmd As ADODB.Command
      Dim rs As ADODB.Recordset
      
      Dim strStartDate As String
      Dim strStartDateTime As String
      Dim strEndDateTime As String
      Dim strYear As String
      Dim strMonth As String
      Dim strLastDay As String
      
      'clear the existing range
      Range(&quot;SalesExtract.Table&quot;).CurrentRegion.Offset(1).EntireRow.Delete
      
      'figure out the start and end datetimes
      strYear = ExtractYear
      strMonth = Right(&quot;0&quot; &amp; ExtractMonth, 2)
      
      strStartDate = &quot;{year}-{month}-{day}&quot;
      strStartDate = Replace(strStartDate, &quot;{year}&quot;, strYear)
      strStartDate = Replace(strStartDate, &quot;{month}&quot;, strMonth)
      strStartDate = Replace(strStartDate, &quot;{day}&quot;, &quot;01&quot;)
      
      strStartDateTime = strStartDate &amp; &quot; 00:00:00&quot;
      
      strLastDay = CStr(Day(DateSerial(Year(strStartDate), Month(strStartDate) + 1, 0)))
      
      strEndDateTime = &quot;{year}-{month}-{day} 23:59:59&quot;
      strEndDateTime = Replace(strEndDateTime, &quot;{year}&quot;, strYear)
      strEndDateTime = Replace(strEndDateTime, &quot;{month}&quot;, strMonth)
      strEndDateTime = Replace(strEndDateTime, &quot;{day}&quot;, strLastDay)
          
  
  Private Sub OutputResults(Level As String, Company As String, Directory As String)
      
      Dim wb As Workbook
      
      Set wb = Workbooks.Add
      
      Dim strSheet As String
      
      If Level = &quot;SUMMARY&quot; Then
          strSheet = &quot;SummaryFilter&quot;
      ElseIf Level = &quot;DETAIL&quot; Then
          strSheet = &quot;DetailFilter&quot;
      Else
          'raise error
      End If
      
      Call ThisWorkbook.Worksheets(strSheet).Range(strSheet &amp; &quot;.Table&quot;).Copy
      
      Call wb.Worksheets(1).Range(&quot;A1&quot;).PasteSpecial(xlPasteValues)
      
      Call ThisWorkbook.Worksheets(strSheet).Range(strSheet &amp; &quot;.ReplacementHeader&quot;).Copy
      
      Call wb.Worksheets(1).Range(&quot;A1&quot;).PasteSpecial(xlPasteValues)
      
      wb.Worksheets(1).Name = Level &amp; &quot; &quot; &amp; Company
      
      Application.DisplayAlerts = False
      Call wb.SaveAs(Directory &amp; &quot;\Sales Extract - &quot; &amp; Level &amp; &quot; &quot; &amp; Company &amp; &quot;.xlsx&quot;)
      Application.DisplayAlerts = True
      
      Call wb.Close
      
      Set wb = Nothing
      
  End Sub
  
  Private Sub FilterData(FilterRng As Range, CriteriaRng As Range, CopyToRng As Range, NameMe As String, Optional FilterUnique As Boolean)
      With CopyToRng
          If WorksheetFunction.CountA(.Offset(1, 0).Resize(1, .Columns.Count)) &lt;&gt; 0 Then
              CopyToRng.CurrentRegion.Offset(1, 0).ClearContents
          End If
      End With
  
      FilterRng.AdvancedFilter _
          Action:=xlFilterCopy, _
          CriteriaRange:=CriteriaRng, _
          CopyToRange:=CopyToRng, _
          Unique:=FilterUnique
      CopyToRng.CurrentRegion.Name = NameMe
  End Sub
  
  Private Sub CleanUpThisWorkbook()
      
      Range(&quot;SalesExtract.Table&quot;).Offset(1).EntireRow.Delete
      Range(&quot;SummaryFilter.Table&quot;).Offset(1).EntireRow.Delete
      Range(&quot;DetailFilter.Table&quot;).Offset(1).EntireRow.Delete
      
  End Sub
  </code></pre>