new line character in cell

X

xgnitesh

Hi
I am using the following piece of code to assign a text to a cell.

Cells(row, col).Value = GetAttribValue(objAttrib, strAttribName)

The function GetAttribValue returns a simple VB string that contains
some vbCrLf 's (new line characters).

I find that the text that actually gets displayed in the cell actually
contains some extra vbCr or vbLf characters inserted just before the
original vbCrLf. I am not sure how excel inserts these extra
characters by itself.

How can I avoid this problem.

Thanks for any help.

Regards
Nitesh Gupta
 
X

xgnitesh

Hi Mangesh

Thanks for your interest.
However the code I am using is already posted:
Cells(row, col).Value = GetAttribValue(objAttrib, strAttribName)
I am simply assigning a string variable to a cell value. You may
consider this

Cells(1, 1).Value = "Hello" + vbCrLf + "World"

Put the above line of code in a button click or sheet load method. You
will see that there is an extra character vbCr inserted before the
actual vbCrLf

Nitesh
 
M

mangesh_yadav

This is from the help:

vbCrLf Chr(13) + Chr(10) Carriage return–linefeed combination
vbCr Chr(13) Carriage return character
vbLf Chr(10) Linefeed character

Manges
 
X

xgnitesh

Thanks Mangesh

This works fine:

Cells(1, 1).Value = "Hello" + Chr(10) + "World"

Regards
Nitesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top