VBA删除空白行列

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

 

上一篇:读取行和列的值


下一篇:恐龙部落APP系统开发