其他分享
首页 > 其他分享> > 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

 

标签:VBA,LastColumn,Sub,行列,ActiveSheet,Long,空白,LastRow,UsedRange
来源: https://www.cnblogs.com/defifind/p/12048325.html