[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

replace carriage return with \&lf;

Posted on 2009-02-09
10
Medium Priority
?
861 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

0
Comment
Question by:itortu
  • 5
  • 3
  • 2
10 Comments
 

Author Comment

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

but it does not work.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23593361
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
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23593402
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:itortu
ID: 23593740
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.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1800 total points
ID: 23598098
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
0
 
LVL 13

Assisted Solution

by:game-master
game-master earned 200 total points
ID: 23607924


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
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23608556
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
0
 
LVL 13

Expert Comment

by:game-master
ID: 23619282

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
0
 

Author Closing Comment

by:itortu
ID: 31544600
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.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23808744
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question