Link to home
Start Free TrialLog in
Avatar of itortu
itortuFlag for United States of America

asked on

replace carriage return with \&lf;

How do I replace a carriage return character from an excel cell?

This is how I assign the cell contents:

xComments = Cells(CurrRow, 5)


the cell can contian:

This is just a test of
carriage returns issue
on Batch Insert/Update

I need to replace the carriage return with \&lf;
so this way when the contents of the excel sheet are written to a script that will perform a insert, the contents would still read the same way:

This is just a test of
carriage returns issue
on Batch Insert/Update

Avatar of itortu
itortu
Flag of United States of America image

ASKER

I have tried to do it this way: xComments = Trim$(Replace(Cells(CurrRow, 5), vbCrLf, "\&lf;"))

but it does not work.
Avatar of Chris Bottomley
In a cell it uses the vertical tab as I think its called anyway NOT vbcrlf but char(10)-sheet or CHR(10)-vba

xComments = Trim$(Replace(Cells(CurrRow, 5), chr(10), "\&lf;"))

Chris
Also just confirmed the constant associated with chr(10) is vblf i.e. if you prefer:

xComments = Trim$(Replace(Cells(CurrRow, 5), vblf, "\&lf;"))

Chris
Avatar of itortu

ASKER

Hi Chris,

You are right I was using the wrong constant. I found that out on the post made by Darius on this forum:http://www.developerfusion.com/forum/thread/23605/


One question, would that line still work when the white square is found in one of the cells?

Is there a way to check the text string for carriage return or the white square, or a line feed within an if statement and apply the appropriate formatting?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
GAme-master,

I think you will find the question was already answered at the second post and confirmed in the fourth one, it is as such awaiting the author closure.

Chris

Chris...

I used chr(13) and I think none of the post states it though...
If the question already answered, my apology though...


game-master
Avatar of itortu

ASKER

I am giving game-mster 50 points for taking the time to look at the question and offer a legit solution. I hope this does not upset you Chris.

Thank you very much for your help.
itortu

For why could I be upset ... they are your points to do with as you please.  My comment earlier to game-master was because vbcr = chr(13) and vblf=chr(10).

However the use of the chr method was new information in the post so whilst less clear in terms of what it was doing it was a reasonable alternative approach and as such it is fair that you rewarded the information hence "for why could I be upset"

See you around
Chris