title: Enquoting a cell value in double quotes: Excel VBA Macro
body: <p><br />
  I want to put double quotes inside all cells in a particular column.
  I have wrote the code to put double quotes but the problem is it is putting 3 double quotes around the value.</p>
  
  <pre><code> For Each myCell In ActiveWorkbook.Sheets("Sheet1").Range("B:B")
          If myCell.Value &lt;&gt; "" Then
              myCell.Value = Chr(34) &amp; myCell.Value &amp; Chr(34)
          End If
   Next myCell
  </code></pre>
  
  <p>The basic requirement is to split the excel file according to column B and save them as CSV files.
  <br>
  In the split filed, the values of column B and D must be enclosed within double quotes.</p>
  
  <p>Full Code :</p>
  
  <pre><code>Option Explicit
  
  Sub ParseItems()
  Dim LR As Long, Itm As Long, MyCount As Long, vCol As Long
  Dim ws As Worksheet, MyArr As Variant, vTitles As String, SvPath As String
  Dim myCell As Range, transCell As Range
  
  'Sheet with data in it
     Set ws = Sheets("Sheet1")
  
  'Path to save files into, remember the final \
      SvPath = "D:\SplitExcel\"
  
  'Range where titles are across top of data, as string, data MUST
  'have titles in this row, edit to suit your titles locale
  'Inserting new row to act as title, copying the data from first row in title, row deleted after use
      ws.Range("A1").EntireRow.Insert
      ws.Rows(2).EntireRow.Copy
      ws.Range("A1").Select
      ws.Paste
      vTitles = "A1:Z1"
  
  'Choose column to evaluate from, column A = 1, B = 2, etc.
     vCol = 2
     If vCol = 0 Then Exit Sub
  
  'Spot bottom row of data
     LR = ws.Cells(ws.Rows.Count, vCol).End(xlUp).Row
  
  'Speed up macro execution
     Application.ScreenUpdating = False
  
  'Get a temporary list of unique values from key column
      ws.Columns(vCol).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ws.Range("EE1"), Unique:=True
  
  'Sort the temporary list
      ws.Columns("EE:EE").Sort Key1:=ws.Range("EE2"), Order1:=xlAscending, Header:=xlYes, _
         OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
  
  'Put list into an array for looping (values cannot be the result of formulas, must be constants)
      MyArr = Application.WorksheetFunction.Transpose(ws.Range("EE2:EE" &amp; Rows.Count).SpecialCells(xlCellTypeConstants))
  
  'clear temporary worksheet list
      ws.Range("EE:EE").Clear
  
  'Turn on the autofilter, one column only is all that is needed
      'ws.Range(vTitles).AutoFilter
  
  'Loop through list one value at a time
      For Itm = 1 To UBound(MyArr)
          ws.Range(vTitles).AutoFilter Field:=vCol, Criteria1:=MyArr(Itm)
          'transCell = ws.Range("A2:A" &amp; LR)
          ws.Range("A2:A" &amp; LR).EntireRow.Copy
          Workbooks.Add
          Range("A1").PasteSpecial xlPasteAll
          Cells.Columns.AutoFit
          MyCount = MyCount + Range("A" &amp; Rows.Count).End(xlUp).Row - 1
  
  
  
          For Each myCell In ActiveWorkbook.Sheets("Sheet1").Range("B:B")
              If myCell.Value &lt;&gt; "" Then
                 myCell.Value = Chr(34) &amp; myCell.Value &amp; Chr(34)
              End If
          Next myCell
  
  
  
          ActiveWorkbook.SaveAs SvPath &amp; "po" &amp; MyArr(Itm) &amp; ActiveWorkbook.Sheets("Sheet1").Range("D1") &amp; "." &amp; Date2Julian(Date), xlCSV, local:=False
          ActiveWorkbook.Close False
  
          ws.Range(vTitles).AutoFilter Field:=vCol
      Next Itm
  
  'Cleanup
      ws.Rows(1).EntireRow.Delete
      ws.AutoFilterMode = False
      Application.ScreenUpdating = True
  End Sub
  
  Function Date2Julian(ByVal vDate As Date) As String
  
      Date2Julian = Format(DateDiff("d", CDate("01/01/" _
                    + Format(Year(vDate), "0000")), vDate) _
                    + 1, "000")
  
  
  
  End Function
  </code></pre>
  
  <p>Sample Input Data :</p>
  
  <pre><code>24833837    8013    70  1105
  25057089    8013    75  1105
  25438741    8013    60  1105
  24833837    8014    70  1106
  25057089    8014    75  1106
  25438741    8014    60  1106
  </code></pre>
  
  <p>Expected Output is Two files created with following data </p>
  
  <p><br>File 1 : </p>
  
  <pre><code>24833837,"8013",70,1105
  25057089,"8013",75,1105
  25438741,"8013",60,1105
  </code></pre>
  
  <p>File 2: </p>
  
  <pre><code>24833837,"8014",70,1106
  25057089,"8014",75,1106
  25438741,"8014",60,1106
  </code></pre>
  
  <p>Resultant Output :</p>
  
  <p>File 1 : </p>
  
  <pre><code>24833837,"""8013""",70,1105
  25057089,"""8013""",75,1105
  25438741,"""8013""",60,1105
  </code></pre>
  
  <p>Same for File 2</p>
  
  <p>Kindly help. :)</p>