VBA删除空白行列

 1 '删除空行
 2 Sub DeleteEmptyRows()
 3 Dim LastRow As Long, r As Long
 4 LastRow = ActiveSheet.UsedRange.Rows.Count
 5 LastRow = LastRow + ActiveSheet.UsedRange.Row - 1
 6 
 7 For r = LastRow To 1 Step -1
 8     If WorksheetFunction.CountA(Rows(r)) = 0 Then Rows(r).Delete
 9     Next r
10     
11 End Sub
12 '删除空列
13 Sub DeleteEmptyColumns()
14 Dim LastColumn As Long, c As Long
15 LastColumn = ActiveSheet.UsedRange.Columns.Count
16 LastColumn = LastColumn + ActiveSheet.UsedRange.Column
17 
18 For c = LastColumn To 1 Step -1
19     If WorksheetFunction.CountA(Columns(c)) = 0 Then Columns(c).Delete
20     Next c
21     
22 End Sub
View Code

 

posted @ 2019-12-16 11:45  defifind  阅读(741)  评论(0编辑  收藏  举报