Carriage Return characters removing - Interesting case

rohit1978

New Member
Joined
Jun 8, 2009
Messages
3
Hello,
We have an excel spreadsheet which users fill out and send it to us. We convert that in a CSV file and then send it to Oracle for uploading.

In excel file , we observed that there were some carriage return characters which would create issues while loading the data in oracle tables. so, we wrote following macro

Sub replacer()
Dim MyChar
MyChar = Chr(10)
Worksheets("Sheet1").Columns("A:A").Replace _
What:=MyChar, Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True

End sub

which replaces the carriage return from the cells. However, this macro didn't work for the cells which have their text copied from a webpage text area. Users had used enter key in the text area and while they copied the data from text area to excel, it looked like a carriage return key but since it was not removed by the macro, I am not sure which character that is.

Anyone with any possible directions to go about removing those apparent carriage return characters which may not be carriage returns in reality?

Please help,
Thanks so much,
Rohit
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You'll need to find out what character it is and adjust your code...

You can use the CODE function to find out the Character #

=CODE(LEFT(A1,1))

where the 1st character of A1 is the character you want to remove..
 
Upvote 0
Also...

Chr(10) is actually a Line Feed. Carriage Return is Chr(13). you should also check for VbCrLf.
 
Upvote 0
Hello,
Thanks for your replies. I checked the code of the character and it came out to be chr(10). My question is why it's not getting replaced with the code I have written?

Here is the sample text from my excel file - There are chr(10)s after every asterik but it won't get replaced by nothing by following code

Sub replacer()
Dim MyChar
MyChar = Chr(10)
Worksheets("Sheet1").Columns("A:A").Replace _
What:=MyChar, Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True


=====================================================
Sample Text
=====================================================
Sample Text - There are chr(10)s after asterik but they are not getting replaced :*
-- A;*
-- B;*
-- C;*
-- D)
=====================================================
 
Upvote 0
This works for me

Rich (BB code):
Sub replacer()
Dim MyChar
MyChar = Chr(10)
Worksheets("Sheet1").Columns("A:A").Replace _
What:=MyChar, Replacement:="", _
SearchOrder:=xlByRows, MatchCase:=True
End Sub
 
Upvote 0
By rows didn't work for me. It took out the spaces in the entire text and all words were concatenated one after the other :(
 
Upvote 0
Rohit

How are you converting to a CSV file?

Why not use a formula to get rid of the unwanted character(s) rather than find/replace?

Also are you sure there are no other unwanted characters?

PS Why do you have MatchCase:=True?:eek:
 
Upvote 0

Forum statistics

Threads
1,215,775
Messages
6,126,829
Members
449,343
Latest member
DEWS2031

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top