Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default how to remove linebreaks in cells with VBA

I have some excel files that I save as comma delimited text files in order to
import them into a Mysql database.
However, some text cells have linebreaks in them, which results in the part
after the linebreak being put onto a new line in the comma delimited text
file.

The mysql import script treats it as a new record, which should not be the
case.
So I want to make a macro that checks all the cells and removes any
linebreaks in them. Can anyone show me how to do that?

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to remove linebreaks in cells with VBA

Hi Ozzmantsje,

Try somethinhg like:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = Workbooks("MyBook.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

SH.Cells.Replace What:=Chr(10), _
Replacement:=vbNullString, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
End Sub
'<<=============


---
Regards,
Norman

"Ozzmantsje" wrote in message
...
I have some excel files that I save as comma delimited text files in order
to
import them into a Mysql database.
However, some text cells have linebreaks in them, which results in the
part
after the linebreak being put onto a new line in the comma delimited text
file.

The mysql import script treats it as a new record, which should not be the
case.
So I want to make a macro that checks all the cells and removes any
linebreaks in them. Can anyone show me how to do that?

Thanks.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i remove the 0 in the cells excelquester Excel Discussion (Misc queries) 7 November 6th 09 06:45 PM
how do I insert forced linebreaks in cells in Excel Dean Molchovic Petersen Excel Discussion (Misc queries) 2 June 19th 09 02:35 PM
how do I shift the contents of the cells up to remove empty cells. auctioncoach Excel Discussion (Misc queries) 2 February 11th 09 06:15 PM
Remove ' from cells Beamers Excel Discussion (Misc queries) 1 May 17th 06 04:32 PM
Remove Blank Cells within each row David Excel Programming 3 February 17th 06 06:37 PM


All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"