如何删除excel删不尽的空行

2025-03-22 00:19:11
推荐回答(2个)
回答1:

有一种运行宏的办法,自动删除空行:

代码:

Sub 去掉表空行()
Dim i As Long
    i = 2
    Do While i <= Range("a65536").End(xlUp).Row
        If WorksheetFunction.CountA(Rows(i)) = 0 Then
        Rows(i).EntireRow.Delete
        i = i - 1
        GoTo l1
        End If
        
        If Left(Cells(i, 1), 1) = " " Then
        Rows(i).EntireRow.Delete
        i = i - 1
        GoTo l1
        End If
        
l1: i = i + 1
    Loop
    Cells.Select
    Cells.EntireRow.AutoFit
    Cells.EntireColumn.AutoFit
End Sub

这个能去除某一行啥都没有,或者有空格的行。

有一个弊端,就是第一行如果是空行的话,不会删除的。这是我为了打印资料不浪费纸做的。如果对你有帮助,请采纳。

回答2:

全选、排序,空白自然到末尾去了。