title: How to get content from all columns into text file from Excel?
body: <p>I am trying to export my excel data to individual text files for each row. I've looked at various SO questions already and can get a working result for each row but cannot get the content to be filled from all columns from column B and forward. Here is what I have tried.</p>
  
  <p>This is from a VBA programming tut. It outputs all my columns but to only one file:</p>
  
  <pre><code>Sub toXPD()
  
  Dim FilePath As String
  Dim CellData As String
  Dim LastCol As Long
  Dim LastRow As Long
  
  LastCol = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
  LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
  
  CellData = ""
  
  FilePath = Application.DefaultFilePath &amp; "\auth.csv"
  
  Open FilePath For Output As #2
  
  For i = 1 To LastRow
  
      For j = 1 To LastCol
  
          If j = LastCol Then
              CellData = CellData + Trim(ActiveCell(i, j).Value)
          Else
              CellData = CellData + Trim(ActiveCell(i, j).Value) + ","
          End If
  
      Next j
  
      Write #2, CellData
      CellData = ""
  
  Next i
  
  Close #2
  
  MsgBox ("Done")
  
  End Sub
  </code></pre>
  
  <p>I've also tried this from this SO question <a href="https://stackoverflow.com/a/17729496/1055954">Create text Files from every row in an Excel Spreadsheet</a> and it works for creating individual files for each row but only fills content from column B and not the others:</p>
  
  <pre><code>Sub savemyrowsastext()
  Dim x
  
  For Each cell In Sheet1.Range("A1:A" &amp; Sheet1.UsedRange.Rows.Count)
  ' you can change the sheet1 to your own choice
  
      saveText = cell.Text
  
      Open "C:\wamp\www\GeoPC_NG\sogistate\igala_land\" &amp; saveText &amp; ".php" For Output As #1
  
      Print #1, cell.Offset(0, 1).Text
  
      Close #1
  
      Beep ' Sound a tone.
  
      Next x
  
  Next cell
  End Sub
  </code></pre>
  
  <p>I am extremely new to VBA/Macro coding and thought this would be a simple task. I've tried to piece together what was missing from the second set of code with pieces from the first set of code but nothing has worked. How can I get the second set of code to include all columns that have values as the content in each text file?</p>
  
  <p><strong>EDIT: Per @Kumarapush additional answer</strong>
  The content does print on separate lines but outputs like so.</p>
  
  <pre><code>"columnB"
  "columnBcolumnC"
  "columnBcolumnCcolumnD"
  </code></pre>
  
  <p><strong>EDIT 2: This is the complete working code for anyone else that comes across this. It prints all columns from column B forward as the content of the txt file and column A as the title of each file. All thanks to @Kumarapush</strong></p>
  
  <pre><code>Sub toFile()
  
      Dim FilePath As String, CellData As String, LastCol As Long, LastRow As Long
      Dim Filenum As Integer
  
      LastCol = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
      LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
  
      For i = 1 To LastRow
          FilePath = Application.DefaultFilePath &amp; "\" &amp; Trim(ActiveSheet.Cells(i, 1).Value) &amp; ".xpd"
          Filenum = FreeFile
  
          Open FilePath For Output As Filenum
          CellData = ""
  
          For j = 2 To LastCol
          CellData = Trim(ActiveSheet.Cells(i, j).Value)
          Write #Filenum, CellData
  
          Next j
  
          Close #Filenum
  
      Next i
      MsgBox ("Done")
  End Sub
  </code></pre>