word 如何删除空行空格 宏
发布网友
发布时间:2022-05-05 12:54
我来回答
共2个回答
热心网友
时间:2022-06-27 12:55
使用替换的方法,空行就是连续2个段落标记的意思,空格就更简单了,直接替换,替换为里面不打任何东西就完成你的任务了
热心网友
时间:2022-06-27 12:55
Sub 删除空行()'删除工作表中的空行Dim i, s As IntegerDim a As RangeApplication.ScreenUpdating = False '关闭屏幕刷新'MsgBox ActiveSheet.UsedRange.Rows.Count '活动工作表已使用的行数'MsgBox ActiveSheet.UsedRange.Columns.Count
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1 s = 0: Set a = Cells(i, 1) For k = 1 To ActiveSheet.UsedRange.Columns.Count If Cells(i, k) = "" Or Cells(i, k) = "0" Or Cells(i, k) = " " Then '检索空单元格 s = s + 1 '累加 End If Next k If s = ActiveSheet.UsedRange.Columns.Count Then '如果整行为空(2003版) a.EntireRow.Delete shift:=xlUp '删除空行 End IfNext iApplication.ScreenUpdating = True '打开屏幕刷新End Sub
Sub 删含空格空段()' 删含空格空段 Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = " ^p" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAllEnd Sub