Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel-VBA: Unable to Insert Line Breaks

Tags:

newline

excel

vba

I need to insert lines in a cell, but I am unable to insert line breaks.

For example :

line1

line2

line3

With VBA code :

             Ws.Cells(i, 2) = line1 & line2 & line3

I get :

line1 line2 line3

How can I resolve this issue?

like image 827
Wassim AZIRAR Avatar asked Dec 05 '22 16:12

Wassim AZIRAR


1 Answers

Is this what you are trying?

Ws.Cells(i, 2).Value = "line1" & vbnewline & "line2" & vbnewline & "line3"

or

Ws.Cells(i, 2).Value = "line1" & vbCrLf & "line2" & vbCrLf & "line3"

EDIT: Inserted quotes as mentioned in my comments.

like image 76
Siddharth Rout Avatar answered Dec 14 '22 15:12

Siddharth Rout