Excel去除换行符

excel导入时,如果有换行符,则会导致读取错行等乱七八糟的错误。

可以用宏代码的方式对换行进行替换

Sub ReplaceCRLF()
    Dim rg As Range
    Set rg = Sheet1.UsedRange
    Dim str As String
    Dim cell As Range
    
    For Each cell In rg
        str = Replace(cell.Value, Chr(10), "")
        cell.Value = str
    Next
End Sub

 

alt + f11, 打开宏编辑界面,贴入代码。在Sheet1中,选中需要替换的范围,执行即可

 

posted @ 2021-09-28 18:45  客于溟  阅读(548)  评论(0)    收藏  举报