|
公式编辑情况:
1、表格里有海量数据,但是根蜂窝一样有很多空单元格。而且存在空行。
2、要求出表格最大行数和列数
3、删除完全没数据的空行
遇到问题:
1、最后一行的起始单元格和末尾单元格可能没有数据,如何求得最大行数和列数?
2、单元格存在假空现象 用countif找不到空单元格,如何处理?
最后编辑公式如下:
Sub DeleteEmptyRows()
Dim LastRow As Long, r As Long
With ActiveSheet
Set theCell = .Cells.Find("*", .Cells(1), xlValues, xlPart, xlByRows, xlPrevious, False, False, False)
theFinalRow = theCell.Row '获取行数
Set theCell = .Cells.Find("*", .Cells(1), xlValues, xlPart, xlByColumns, xlPrevious, False, False, False)
theFinalColumn = theCell.Column '获取列数
End With
For r = theFinalRow To 1 Step -1
With Application.WorksheetFunction
If .CountIf(Range(r & ":" & r), "<>""") - .CountIf(Range(r & ":" & r), "") < 1 Then Rows(r).Delete‘删除空行,同时解决假空问题
End With
Next r
End Sub
|
|