In this article, we will discuss some methods to remove carriage returns in Excel; including VBA. Often, we copy data from web pages or other workbooks, which contain carriage returns, line breaks with Alt+Enter. Later, if required, we have to remove these carriage returns and line breaks. Luckily, Excel has very easy options to delete these line breaks and now we will discuss those.
How to Remove Carriage Returns in Excel: 3 Easy Ways
1. Delete Carriage Returns Using Find and Replace
We can remove carriage returns manually by Find and Replace option. For example, we have a dataset containing book names with carriage returns.
- At first, select the cells containing line breaks.
- Then, press Ctrl+H from the keyboard. As a result, the Find and Replace window will pop up. Now, go to Find what field and press Ctrl+J. A dot (.) will show up in the box. Keep Replace with field blank. Finally, click the Replace All button.
- Consequently, all the line breaks will be removed.
Read More: How to Insert Carriage Return in Excel Cell
2. Use Excel Functions to Remove Carriage Returns
Excel has some inbuilt functions to remove line breaks. In this method, we will use the combination of SUBSTITUTE and CHAR functions.
- At first, consider a dataset containing color names with carriage return.
- Then, type the following formula in a blank cell:
Here, the formula removes line breaks of Cell B5 and replaces those breaks with commas. On the other hand, Char(10) function returns a line break character.
- Finally, you will get the following result. Use Autofill (+) to copy the formula to other cells.
3. Erase Carriage Returns Using VBA in Excel
If you do not want to use manual ways or formulas to remove line breaks, using VBA can be an excellent option. Suppose we have a book name dataset containing carriage returns. We will follow the below steps to delete those breaks.
- Firstly, go to the sheet containing the dataset and open the code window by clicking the View Code.
- Then, write the following code to the code window.
Option Explicit Sub RemoveCarriageReturns() Dim MyRange As Range Application.ScreenUpdating = False Application.Calculation = xlCalculationManual For Each MyRange In ActiveSheet.UsedRange If 0 < InStr(MyRange, Chr(10)) Then MyRange = Replace(MyRange, Chr(10), "") End If Next Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic End Sub
- Lastly, run the code, and line breaks will be removed.
Read More: How to Find Carriage Return in Excel
Download the Practice Workbook
You can download the practice workbook that we have used to prepare this article.
In this article, we have discussed some easy methods to remove carriage returns in Excel. So, hopefully, these methods will help you. Download and practice our workbook for all the methods mentioned above. If you have any queries, please feel free to comment here.