Excel: how do I remove all carriage returns from a cell?

后端 未结 5 1138
青春惊慌失措
青春惊慌失措 2020-12-28 15:55

I want to get rid of all the carriage returns in my cell. How do I do this?

相关标签:
5条回答
  • 2020-12-28 16:32

    =Clean(A1)

    This command can be found in Excel under the formulas tab > text.

    0 讨论(0)
  • 2020-12-28 16:39

    Select the cell or cells, click Data/Text To Columns form Excel's menu bar, choose the Delimited option on the first dialog page, click the Next button, uncheck everything except Other and type Ctrl+J into the field next to it (you won't see anything in that box, but the column layout chart will show that it is being split at the line feeds (they are not carriage returns)... then just click the Finish button.

    0 讨论(0)
  • 2020-12-28 16:45
    Sub RemoveLineBreaks()
        Application.ScreenUpdating = False
        Dim rngCel As Range
        Dim strOldVal As String
        Dim strNewVal As String
    
        For Each rngCel In Selection
            If rngCel.HasFormula = False Then
                strOldVal = rngCel.Value
                strNewVal = strOldVal
                Debug.Print rngCel.Address
    
                Do
    
                strNewVal = Replace(strNewVal, vbLf, " ")
    
                If strNewVal = strOldVal Then Exit Do
                    strOldVal = strNewVal
                Loop
    
                If rngCel.Value <> strNewVal Then
                    rngCel = strNewVal
                End If
            End If
            rngCel.Value = Application.Trim(rngCel.Value)
        Next rngCel
        Application.ScreenUpdating = True
    End Sub
    
    0 讨论(0)
  • 2020-12-28 16:49

    =CLEAN(A1)

    Clean removes all nonprintable characters from text. -- Excel Help Documentation

    0 讨论(0)
  • Assuming your cell is in A1, you can use the following formula:

    =SUBSTITUTE(A1,CHAR(10),"")
    

    Depending on the carriage return, you may have to use char(13) instead of char(10).

    0 讨论(0)
提交回复
热议问题