We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

replace carriage return with \&lf;

itortu
itortu asked
on
Medium Priority
880 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

Author

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

but it does not work.
CERTIFIED EXPERT
Top Expert 2011

Commented:
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
CERTIFIED EXPERT
Top Expert 2011

Commented:
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

Author

Commented:
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.
CERTIFIED EXPERT
Top Expert 2011
Commented:
The white square as such represents unprintable characters, (yeah CR & LF are printable!).  The easiest thing for a limited number of checks, i.e. cr/lf/crlf is a replace which gets rid if present and is otherwise inobtrusive:

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

Chris

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


good morning!
try this approach...

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


chr(13) is the ASCII code of carriage return...


game-master
CERTIFIED EXPERT
Top Expert 2011

Commented:
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

Author

Commented:
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.
CERTIFIED EXPERT
Top Expert 2011

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.