How to display newline in Excel?

January 12, 2008

The commonly used to display newline in Visual Basic is using VbCrLF. But the problem is you will see a small rectangle at the end of the line.

Excel New Line

Visual Basic:
  1. Dim strFirstLine As String
  2. Dim strSecondLine As String
  3.  
  4. strFirstLine = "This is the first line"
  5. strSecondLine = "This is second line"
  6.  
  7. Worksheets("Sheet1").Range("b4").Value = _
  8. strFirstLine & vbCrLf & strSecondLine

To solve this problem, you will need to change the code from VbCrLF to VbLf.

Visual Basic:
  1. Dim strFirstLine As String
  2. Dim strSecondLine As String
  3.  
  4. strFirstLine = "This is the first line"
  5. strSecondLine = "This is second line"
  6.  
  7. Worksheets("Sheet1").Range("b4").Value = _
  8. strFirstLine & vbLf & strSecondLine

Excel New Line