title: excel vba exporting csv file quote qualifiers
body: <p>I am new to vba and need some help as I can't work this out</p>
  
  <p>When trying to save some specific content from one of the worksheets in an excel workbook into a CSV file,I can't get the right output format. This is critical as  some columns need text qualifiers and others do not and I have to get it right as the file will go into a enterprise solution.</p>
  
  <p>I have 5 columns A-E that holds data I need to export as a csv, columns A,C &amp; E need text qualifiers, but B &amp; D do not.</p>
  
  <p>The csv file has 2 header rows, which do not have any " qualifiers</p>
  
  <p>I am trying to get this to work but have 2 issues
  1) Columns A,C &amp; E need to be in quotes, with B &amp; D not in quotes
  2) The header in row 1 has extra ,,,, on the end which I want to remove</p>
  
  <p>The code I am using is below, and I've attached an image of a sample file to bring it to life.</p>
  
  <p>The file does the following
  1) Selects a dynamic range of rows within columns A-E
  2) Saves as a specific name with data &amp; time included it it.</p>
  
  <pre><code>Sub SaveDynamicRangeAsCSVFile_IncTextDelimiters()
  
  'Turn off screen updating for performance and prevent dizziness
       Application.ScreenUpdating = False
  
  'Set-up
      Dim MyPath As String
      Dim MyFileName As String
      Dim WB1 As Workbook, WB2 As Workbook
      Set WB1 = ActiveWorkbook
      MyFileName = "ProdTabData-" &amp; Format(Date, "yyyymmdd-") &amp; Format(Time, "hhmmss")
      FullPath = WB1.Path &amp; "\" &amp; MyFileName
  
  'Dynamic range identified
      Application.ScreenUpdating = False
      Range("A5:E" &amp; Cells(Rows.Count, 1).End(xlUp).Row).Copy
      Set WB2 = Application.Workbooks.Add(1)
      WB2.Sheets(1).Range("A1").PasteSpecial xlPasteValues
      Application.DisplayAlerts = False
  
  'save file
      If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName &amp; ".csv"
      With WB2
          .SaveAs Filename:=FullPath, FileFormat:=xlCSV, CreateBackup:=False
          .Close False
      End With
      Application.DisplayAlerts = False
  
  'Turn on screen updating
          Application.ScreenUpdating = True
  
  End Sub
  </code></pre>
  
  <p>The output it gives me is:</p>
  
  <p>Export file name,,,,</p>
  
  <p>Column1,Column2,Column3,Column4,Column5</p>
  
  <p>name 1,Group1,Description 1,1,0</p>
  
  <p>Name 2,Group2,Description 2,1,0</p>
  
  <p>name 3,Group3,Description 3,1,0</p>
  
  <p>name 4,Group4,Description 4,1,0</p>
  
  <p>name 5,Group5,Description 5,1,0</p>
  
  <p>name 6,Group6,Description 6,1,0</p>
  
  <p>name 7,Group7,Description 7,1,0</p>
  
  <p>I need it to be:</p>
  
  <p>Export file name</p>
  
  <p>Column1,Column2,Column3,Column4,Column5</p>
  
  <p>"name 1",Group1,"Description 1",1,"0"</p>
  
  <p>"Name 2",Group2,"Description 2",1,"0"</p>
  
  <p>"name 3",Group3,"Description 3",1,"0"</p>
  
  <p>"name 4",Group4,"Description 4",1,"0"</p>
  
  <p>"name 5",Group5,"Description 5",1,"0"</p>
  
  <p>"name 6",Group6,"Description 6",1,"0"</p>
  
  <p>"name 7",Group7,"Description 7",1,"0"</p>
  
  <p>I keep looping around different solutions, so need some expert guidance please.</p>
  
  <p>All suggestions welcome as getting desperate
  Thanks</p>
  
  <p><a href="https://i.stack.imgur.com/X3nRO.jpg" rel="nofollow noreferrer">Excel file image</a></p>