Excel批量删除空行和空列

张文保 更新 2 分钟阅读 3,934 阅读

删除空余行宏代码:

Dim LastRow As Long, r As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
LastRow = LastRow + ActiveSheet.UsedRange.Row -1
For r = LastRow To 1 Step -1
If WorksheetFunction.CountA(Rows(r)) = 0 Then Rows(r).Delete
Next r

删除空余列宏代码:

Dim LastColumn As Long, c As Long
LastColumn = ActiveSheet.UsedRange.Columns.Count
LastColumn = LastColumn + ActiveSheet.UsedRange.Column
For c = LastColumn To 1 Step -1
If WorksheetFunction.CountA(Columns(c)) = 0 Then Columns(c).Delete
Next c

 

标签
版权声明

本文标题:《Excel批量删除空行和空列》

本文链接:https://zhangwenbao.com/excel-batch-deleting-empty-and-empty-columns.html

版权声明:本文原创,转载请注明出处和链接。许可协议: CC BY-NC-SA 4.0

继续阅读
发表评论
支持 Ctrl + Enter 提交