title: VBA code to save Excel sheet as tab-delimited text file
body: <p>I found this code and tried it. It works fine, but in the saved text file the first column has blank space (for all rows). I am unable to fix this code.</p>
  <pre><code>Sub ExportRange()
  Dim ExpRng As Range
  Open ThisWorkbook.Path &amp; &quot;\AllDXL.txt&quot; For Output As #1
  Set ExpRng = Worksheets(&quot;Sheet1&quot;).Range(&quot;A1&quot;).CurrentRegion
  FirstCol = ExpRng.Columns(1).Column
  LastCol = FirstCol + ExpRng.Columns.Count - 1
  FirstRow = ExpRng.Rows(1).Row
  LastRow = FirstRow + ExpRng.Rows.Count - 1
  For r = FirstRow To LastRow
   Data = &quot;&quot;
   For c = FirstCol To LastCol
    '  data = ExpRng.Cells(r, c).Value
    Data = Data &amp; vbTab &amp; ExpRng.Cells(r, c).Value
  Next c
  Print #1, Data
  Next r
  Close #1
  End Sub
  </code></pre>