Reputation: 25
after running the code it is showing the text like this "AASD FDG HJK LSDH YTWIN " in a cell but i need those words in a cell wrapped like
AASD
FDG
HJK
LSDH
YTWIN
this in one cell. what changes needs to be done to get like that for this code
Ws.Range("E" & R).Value = "AASD FDG HJK LSDH YTWIN "
Upvotes: 0
Views: 369
Reputation: 29592
To have a line break in an Excel cell, use a LineFeed character. In VBA, a constant vbLf
is defined for that. Furthermore, the cell needs to have the WrapText
-property set.
So you can use
With ws.Range("E" & R)
.WrapText = True
.Value = "AASD" & vbLf & "FDG" & vbLf & "HJK" & vbLF & "LSDH" & vbLF & "YTWIN"
' Or use
.Value = Replace("AASD FDG HJK LSDH YTWIN ", " ", vbLf)
end With
Upvotes: 1
Reputation: 236
Your question is answered here
In your case, the solution would be:
Ws.Range("E" & R).Value = "AASD" & chr(10) & "FDG" & chr(10) & "HJK" & chr(10) & "LSDH" & chr(10) & "YTWIN "
As mentioned in linked post, this automatically sets WrapText to True.
Upvotes: 1