Replacing line breaks within cells

anxoperez

Active Member
Joined
Oct 3, 2007
Messages
254
I need to replace all the breaks within cells with the forward slash symbol

/

I have tried to do a find and replace by pasting the break symbol but that does not work (I remember doing that in Word a few years back and it used to work).

I need to do this substitution in Column AG and AH.

If someone can help.
 
ok,

=CODE(MID(A1,5,1))

Change A1 to any cell that contains a string that contains line breaks.
Change 5 to whatever the position number in that string is a line break.

Here's a string:
Hello anxoperez

the letter o is in the 5th position of that string..
So =CODE(MID(A1,5,1)) would return 111 (the ASCII code for the letter o)

Now that formula will tell you the ASCII code for the character that looks like a line break.
Use that code when you go to find/replace
in the Find What box, Hold ALT and type that code.
 
Last edited:
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What jonmo1 is saying is to put this formula somewhere on your sheet but change the reference A1 to one of your cells that contains the line breaks and change the 5 to the number that represents the position that the 1st line break occurs e.g. if the cell containing the text with lne breaks is in cell AG2 and the 1st line break is at character position 12 the formula would be:

=CODE(MID(AG2,12,1)

This formula should then give you a number which is the number to then use in his previous reponse i.e. if the formula returns the value 7 then you would do a search and replace by holding down the ALT key and typing 007 (and replace with nothing) and therefore remove all line breaks from your sheet.
 
Upvote 0
Unless I have done something wrong, it hasn't worked.

I suppose what you have suggested depends on what type of keyboard layout you're using, and I'm using several. Maybe you can paste what the actual symbols I should be typing are so I can try to find them.

I'm using a Mac. I don't know if that changes anything.

The ALT+010 is a PC "thing", so I doubt it will work on a Mac. I don't know the Mac's equivalent to the PC's CTRL key, but on a PC you can use CTRL+J in place of the ALT+010 to do the same thing... try your equivalent of that and see if it will work on the Mac.
 
Upvote 0
Actually,

Perhaps Ricky is right, but I don't even have the privilege of making it that far.

I have understood both of the previous explanations and I have done what you guys have told me, but the formula returns an error.

I was out of time and so I had to do the substitutions manually.

Still, I have had this problem many times and I think it would be interesting to find out the answer.

If you guys are still willing to find solutions, I will gladly listen.
 
Upvote 0
It may be that on Mac it's a different code for line breaks? I know character 13 is also a line break so try this (where A1 is the cell containing your text):

Code:
=SUBSTITUTE(SUBSTITUTE(A1,CHAR(10),"/"),CHAR(13),"/")
 
Upvote 0
I asked this question a few weeks ago and I still have not gotten an answer. Now I need to do another substitution job and I really need to get an answer for my question.

If someone is courageous enough to look into this, I would appreciate it.
 
Upvote 0
I asked this question a few weeks ago and I still have not gotten an answer. Now I need to do another substitution job and I really need to get an answer for my question.

If someone is courageous enough to look into this, I would appreciate it.

Unless you can provide a sample file I don't think I will be able to help.
 
Upvote 0
I am not sure exactly what I am supposed to do with that formula. I understand that is not VBA code, so I have just pasted it onto a random cell.

It returned an error and highlighted the A1 portion of the formula.

Maybe you can elaborate a bit more?


Try This

Open module in VBA

paste

Code:
Public Sub CleanofReturns()
Dim c As Range
'ActiveSheet.UsedRange.Select
For Each c In Selection
    If (Not IsNumeric(c.Value)) And (Not c.HasFormula) Then
 
        c.Value = Replace((c.Value), Chr(10), "/")
    End If
 
Next c
End Sub

Compile

save

Highlight (select) on spreadsheet data requiring conversion

run CleanofReturns macro!!

IT is NOT a spreadsheet function
its a macro for converting the text contents of a cell

it ignores formula's
 
Upvote 0
I think the problem is the Chr(10).

I have a MAC and I believe that does not work. This is what we were talking about in the previous threads.

Am I wrong?
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,246
Members
453,152
Latest member
ChrisMd

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