Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help removing line breaks of 2 kinds from Excel file 2

Status
Not open for further replies.

DannyTEM

Technical User
Jul 18, 2002
60
GB
Hello,

I have an excel database which was exported from a query in business. Line breaks are present but in addition to windows line breaks which apart from the obvious are invisible, those square block symbols are also present. Normally the windows line breaks are no problem and I wold export to csv which is the required format.

However it seems those squares are forcing double breaks so in the CSV files there are extra line break which is causing my php script which processes the csv to fall over.

This has been driving me nuts so any help gratefully received. Thanks, Dan

excelproblem.gif




Dan Morgan -
 
Select the 2 characters, CTRL+H (replace), all with blanks

HTH
--Paul
 
Hi DannyTEM,

The squares are Carriage Returns (ASCII 13 characters). Your source data presumably has Carriage Return / Line Feed combinations and data in Excel cells uses only the Line Feed, leaving the Carriage Return as you see it.

Copy and Paste usually takes care of these things behind the scenes (which is, in a sense, what is happening with your csv creation), but you're not getting your data that way. I don't think there's any way to change them in Excel without using VBA. Basic code would be like ..

Code:
[blue]For Each Cel in [i]Your_Range[/i]
    Cel.Value = Replace(Cel, Chr(13),"")
Next[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi Tony, thanks for that!

One question (I am very Macro illiterate) where you have Your_Range, is that a range as in the range of cells in the column like F1:F9999 or the workbook name?

Thanks

Dan

Dan Morgan -
 
Hi Dan,

It is a range of cells - replace it with, as in your example, [blue]Range("F1:F9999")[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi Tony,

Thanks, still getting a compile error for some reason.

Is there prehaps someother value I am assuming is a reserved name/function when in fact it is a user (me) filled in value?

Code:
For Each Cel In Range("F1:F689")
    Cel.Value = Replace(Cel, Chr(13), "")
Next

Dan Morgan -
 
Hi Dan,

What is the error you are getting?

And where have you put the code?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi Tony,

The error is

Compile Error:
Invalid outside procedure, and it highlights the first line of the macro.

I am Alt+F11 to get to VBA editor, clicking on my sheet on the left, pasting the code in (below), then going to Debug > Compile. it is not showing up in excel either when I go to run a Macro.

Sorry very limited VBA/Macro knowledge.

Dan

Dan Morgan -
 
Hi Dan,

The code should be alright where you put it although it would be better in a code module (to create one, Select Insert > Module from the Menu Bar).

The problem you have is because I just posted a snippet of code and not a whole procedure; it needs to be inside a Sub. Cut and paste this in its entirety to replace what you have ..

Code:
[blue]Sub RemoveCR()

Dim Cel as Range

For Each Cel In Range("F1:F689")
    Cel.Value = Replace(Cel, Chr(13), "")
Next

End Sub[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Okay, it is still leaving squares in some places in the actual csv export viewed in a text editor.

Whats the line break code so I can use that marco to remove all of the windows carriage returns within excel?

I figure if I lose a bit of paragraph formatting it is not the end of the world.

Thanks

Dan

Dan Morgan -
 
Hi Dan,

Well, Line Feeds are Chr(10) but I don't know whether removing all of them will give what you want.

If you get further issues, can you cut and paste text here (including the squares) and, with luck, we'll be able to identify them.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top