title: Create and Write to a text file using an excel macro and VBA
body: <p>I am using a macro and VBA code to create a text file with a specific format. All the data needed to create the text file is gathered from the macro cells.
  I have attached pictures of the macro data file and the output text file (please see below).</p>
  
  <p><a href="https://i.stack.imgur.com/ay25l.png" rel="nofollow noreferrer">excel macro with data</a></p>
  
  <p><a href="https://i.stack.imgur.com/znt2t.png" rel="nofollow noreferrer">Desired output txt format-example</a></p>
  
  <p>Also, below is my VBA code I generated to get data from the macro and create/write into a text file. I still need to figure out how to write it in the specified format (Desired output txt format-example).</p>
  
  <pre><code> Sub ExcelToTxt() 
  'Declaring variables 
  Dim lCounter As Long 
  Dim lLastRow As Long 
  Dim destgroup As String 
  Dim parmlabel as Variant 
  Dim FName As Variant 
  
  'Activate Sheet1 
  Sheet1.Activate 
  
  'Find the last row that contains data 
  With Sheet1 
      lLastRow = .Cells(.Rows.Count, "A").End(xlDown).Row 
  End With
  
  'Create txt file 
  FName = Application.GetSaveAsFilename("", "txt file (*.txt), *.txt") 
  
  'Open FName For Output As #1
  For lCounter = 2 To lLastRow 
      'Read specific data from the worksheet 
      With Sheet1 destgroup = .Cells(lCounter, 19) 
          parmlabel = .Cells(lCounter, 8) 
          If destgroup="trex_15hz" Or destgroup="trex_10hz" Or destgroup="trex_5hz" Then 
              'Write selected data to text file 
              'Write #1, parmlabel 
          End If
      End With
  'Continue looping until the last row 
  Next lCounter 
  
  'Close the text file 
  Close #1 
  
  End Sub
  </code></pre>
  
  <p>Any help with what I need to add in my VBA to create the formatted output txt file will be greatly appreciate it.</p>
  
  <p>Thank you in advance.</p>