title: VBA Loop Print to CSV Output
body: <p>I'm trying to create a CSV output file in VBA but I can't seem to get it. I need to loop through a spreadsheet and pull numbers from column 'I' based on whether column D has a "1" in it or not. Then I want to paste the contents of column 'I' into column 'A' of the CSV output file. Could someone please help me complete this? I'd like to incorporate all of the following:</p>
  
  <pre><code>Sub Test()
  
  Dim FileNum, bOutputLine, bFile As String
  Dim bOUTPUT, iRow As Integer
  
  bOUTPUT = FreeFile                                   'Define bOUTPUT as a FreeFile
  bFile = "C:\Desktop\Test.csv"                        'set the filepath equal to a string
  
  For iRow = 2 To ActiveSheet.UsedRange.Rows.Count
  If Trim(range("D" &amp; iRow)) &lt;&gt; "" Then
  FileNum = Trim(range("I" &amp; iRow))
  End If
  Next
  
  Open bFile For Output As bOUTPUT                     'Open the file
  bOutputLine = FileNum                                
  Print #bOUTPUT, bOutputLine                                                                            
  Close #bOUTPUT                                       'Close the file
  
  End Sub
  </code></pre>