VBA - If a cell ends with more than one char(10), replace it with only one char (10)

LearnNewThings

New Member
Joined
Aug 27, 2019
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I have a column with multiple line text, some of which end with multiple line breaks (char(10)). I want to be able to search the entire column and replace the cells that end with multiple char(10) and replace it with only one char(10). I would like to perform this using VBA and include it within the project I already have ongoing.

Details on the data (small sample of scenarios below):
- Row 1 has 3 lines of text with >1 char(10) at the end of the data
- Row 2 has 2 lines of text with 1 char(10) at the end (this is how they all should be)
- Row 3 has 1 line of text with >1 char(10)

Book1
A
1This is line 1 This is line 2 This is line 3
2This is another 1 This is another 2
3Yet one more
Sheet1
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this:
VBA Code:
Sub MyReplaceMacro()
    Cells.Replace What:="" & Chr(10) & "" & Chr(10) & "", Replacement:="" & Chr(10) & "", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,709
Messages
6,126,383
Members
449,311
Latest member
accessbob

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