VBA for formatting line breaks

afrobea_r

Board Regular
Joined
Aug 16, 2015
Messages
76
Dear Excel Community,

Currently I have multiple cells with data arranged like the example below:
Apple

Orange

Watermelon & Mangosteen


Using this formula :

For Each UsedCell In Selection

Cells.Replace What:=Chr(10), Replacement:=" "

My data gets rearranged to:
AppleOrangeWatermelon &Mangosteen

How can I modify the formula to arrange data in this manner instead.

Apple
Orange
Watermelon & Mangosteen


<tbody>
</tbody>

Essentially I would like to retain the existing paragraphing format but without the level spaces.

Help appreciated!

Thank you!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try:

Code:
Selection.Replace What:=Chr(10) & Chr(10), Replacement:=Chr(10), LookAt:=xlPart
 
Last edited:
Upvote 0
Try:

Code:
Selection.Replace What:=Chr(10) & Chr(10), Replacement:=Chr(10), LookAt:=xlPart


Btw Sir,

If I wish to combine the conditional formatting based on values assigned to adjacent cells, is this correct?

Sub CombinedFormat()
' test Macro
With Range("L12").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWindow.SmallScroll Down:=3


If Range("Q3") = "2" Then


Cells.Replace What:=Chr(10) & Chr(10), Replacement:=Chr(10), LookAt:=xlPart


End If


If Range("Q3") = "1" Then


Cells.Replace What:=Chr(10), Replacement:=" "


End If


End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,395
Messages
6,119,265
Members
448,881
Latest member
Faxgirl

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