|
Option Explicit
Sub 选定区域单元格回车换行()
Dim Arr As Variant
Dim hh As Long, hs As Long, Lh As Long, Ls As Long
hh = Selection.Areas.Count
If hh <> 1 Then
MsgBox "选定了多个区域,无法处理回车换行符", vbInformation, "不可选定多个区域"
Else
hs = Application.Selection.Rows.Count
Ls = Application.Selection.Columns.Count
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False '删除空格
Selection.Replace What:=Chr(10), Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
If hs = 1 And Ls = 1 Then
Selection = Chr(10) & Selection & Chr(10)
Else
Arr = Selection
ReDim Brr(1 To hs, 1 To Ls) As Variant
For hh = 1 To hs
For Lh = 1 To Ls
If Arr(hh, Lh) = "" Then
Brr(hh, Lh) = ""
Else
Brr(hh, Lh) = Chr(10) & Arr(hh, Lh) & Chr(10)
End If
Next Lh
Next hh
Selection = Brr
Set Arr = Nothing
Erase Brr
End If
End If
End Sub
选定区域单元格回车换行.rar
(19.21 KB, 下载次数: 6)
|
评分
-
2
查看全部评分
-
|