Excel Formula Help: Delete Spaces before ever line breaks

hasisanchez

New Member
Joined
Mar 4, 2014
Messages
1
Hi Experts,

I am editing over 200k records and I need help with a formula..
I have a lot of texts in every cell with line breaks and there are spaces before each line breaks and these should go away. Can you help?

Thanks!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Select the range of your data
Ctrl G to open Find and Replace
Find what: SPACE and CTRL J ('note: you will see nothing but a tiny blinking dot at the bottom on the text box)
Replace what: CTRL J
Replace all





Hi Experts,

I am editing over 200k records and I need help with a formula..
I have a lot of texts in every cell with line breaks and there are spaces before each line breaks and these should go away. Can you help?

Thanks!
 
Upvote 0
Give this macro a try (change the column ranges highlighted in red to whatever column range(s) your text is in)...

Rich (BB code):
Sub RemoveSpacesBeforeLineBreaks()
  Dim Cell As Range, CellText As String
  With Intersect(Range("C:E,H:H"), ActiveSheet.UsedRange)
    Do While Not .Find(" " & vbLf, , xlValues, xlPart) Is Nothing
      .Cells.Replace " " & vbLf, vbLf, xlPart
    Loop
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,035
Messages
6,134,123
Members
449,861
Latest member
DMJHohl

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