excel 添加換行符,去除換行符:


excel 中添加換行符:

  :alt+enter

去掉excel中的換行符有三種方法:

注:解決過程中翻閱其他博客,看到如下方式:

1、看到有的說全選后“取消自動換行”,保存后,再打開,依然存在換行符

2、ctrl+H,然后按住alt輸入“10”或者“0010”,然后替換,測試無效,可能我操作不對

解決辦法:

M1:

  1. 直接查找替換,選中你要替換的位置or全選(ctrl+a)
  2. 然后按 ctrl+h,打開替換界面
  3. 在替換內容窗口,輸入ctrl+j,看起來是空的,但是你能看到一個點閃爍。
  4. 在替換為窗口,輸入你要替換的內容,什么也不輸入表示刪掉
  5. 然后按照需要選擇全部替換,或者替換

M2 and M3:不翻譯了,看起來有點麻煩

原文鏈接:https://www.ablebits.com/office-addins-blog/2013/12/03/remove-carriage-returns-excel/

Delete line breaks using Excel formulas

Pros: you can use a formula chain / nested formulas for complex cell text processing. For example, it is possible to remove carriage returns and then eliminate excess leading and trailing spaces and those between words.

Or you may need to delete carriage returns to use your text as an argument of another function without changing the original cells. For example, if you want to be able to use the result as an argument of the function =lookup ().

Cons: you'll need to create a helper column and follow many extra steps.

  1. Add the helper column to the end of your data. You can name it "1 line".
  2. In the first cell of the helper column (C2), enter the formula to remove / replace line breaks. Here you can see several helpful formulas for different occasions:
    • Handle both Windows and UNIX carriage return/ line feeds combinations.
      =SUBSTITUTE(SUBSTITUTE(B2,CHAR(13),""),CHAR(10),"")
    • The next formula will help you replace line break with any other symbol (comma+space). In this case lines will not join and extra spaces will not appear. 
      =TRIM(SUBSTITUTE(SUBSTITUTE(B2,CHAR(13),""),CHAR(10),", ")
    • If you want to remove all nonprintable characters from text, including line breaks:
      =CLEAN(B2)

    Excel formula to delete carriage returns from cells

  3. Copy the formula across the other cells in the column.
  4. Optionally, you can replace the original column with the one where the line breaks were removed:
    • Select all cells in column C and press Ctrl + C to copy the data to clipboard.
    • Now pick the cell B2 and press the Shift + F10 shortcut. Then just press V.
    • Remove the helper column.

VBA macro to get rid of line breaks

Pros: Being created once, can be reused in any workbook.

Cons: you need to have the basic knowledge of VBA.

The VBA macro from the example below deletes carriage returns from all cells in the currently opened worksheet (active worksheet).

 
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

If you don't know VBA really well, see How to insert and run VBA code in Excel

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM