title: How do I remove Newline and or Carrige return characters in an Excel cell
body: <p>I have an Excel sheet that I need to convert into a csv file for import into a database.  The Excel sheet has one column of cells that some have return characters, I think because I can't see what it really is there, causing my csv file to have extra records that should be apart of the previous recordset.  I tried Vba code around it but only got some of the return characters, code below.</p>
  
  <pre><code>Public Sub GetCarriageReturn()
  
  Dim mString As String
  
  
      With ActiveSheet
          lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
      End With
  
      For i = 2 To lastRow
          mString = Cells(i, "B")
          LfPosition = InStr(mString, vbLf) 'Chr(10)
          'MsgBox LfPosition
          If LfPosition &gt; 0 Then
              mNewString = Left(mString, LfPosition - 2) &amp; " " &amp; Mid(mString, LfPosition + 1, 20)
              Trim (mNewString)
              'Debug.Print mNewString
              Cells(i, "B").Value = mNewString
          End If
  
          CrPosition = InStr(mString, vbCr) 'Chr(10)
          'MsgBox CrPosition
          If CrPosition &gt; 0 Then
              mNewString = Left(mString, CrPosition - 2) &amp; " " &amp; Mid(mString, CrPosition + 1, 20)
              Trim (mNewString)
              'Debug.Print mNewString
              Cells(i, "B").Value = mNewString
          End If
      Next i
  
  End Sub
  </code></pre>
  
  <p>What am I missing here?  Any assistance would be greatly appreciated.</p>