VBA - removing line breaks

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
I have some cells that have line breaks that values that are split by line breaks. I would like to remove the line breaks in the cell.

Is it possible to assign a range to this VBA script? eg A3:D4

Original CellTransformed Cell
Apple
Orange
Banana
Apple Orange Banana
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
VBA Code:
Sub RemoveLineBreaks()

Dim ws As Worksheet
Dim LastRow As Long
Set ws = Worksheets("TEst1") '<- change sheet name

LastRow = ws.Range("A:B").Find("*", , , , xlByRows, xlPrevious).Row <- looks at last row between column A & B
ws.Range("A2:B" & LastRow).SpecialCells(xlCellTypeConstants).Replace Chr(10), " " '<- If needed, insert split between quotes. I only needed a space. Change range as required

End Sub
 
Last edited by a moderator:
Upvote 0
Solution
@Ananthak275
When posting code, please use one of the relevant Code tag options, not the Quote tags. I have fixed it for you this time.

1675298972479.png
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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