在我的代码运行后,我想不出一种方法来删除空行。这段代码运行良好,它将两组数据进行比较以显示差异,并返回主键及其相关行。
我已经尝试了多个删除函数/VBA代码,但似乎找不到一个我想要的。下面的代码删除空行,但不删除包含公式的行。
Public Sub DeleteAllEmptyRows()
Dim LastRowIndex As Integer
Dim RowIndex As Integer
Dim UsedRng As Range
Set UsedRng = ActiveSheet.UsedRange
LastRowIndex = UsedRng.Row - 1 + UsedRng.Rows.Count
Application.ScreenUpdating = False
For RowIndex = LastRowIndex To 1 Step -1
If Application.CountA(Rows(RowIndex)) = 0 Then
Rows(RowIndex).Delete
End If
Next RowIndex
Application.ScreenUpdating = True
End Sub删除了不必要的行,以提供格式化的行。
发布于 2019-07-25 04:20:24
下面的代码将删除没有显示值的活动工作表的已用范围内的所有行,即包含不满足显示条件的公式的行和完全空白的行:
Public Sub DeleteAllEmptyRows()
Dim LastRowIndex As Integer, RowIndex As Integer
Dim UsedRng As Range
Application.ScreenUpdating = False
Set UsedRng = ActiveSheet.UsedRange
LastRowIndex = UsedRng.Row - 1 + UsedRng.Rows.Count
For RowIndex = LastRowIndex To 1 Step -1
If WorksheetFunction.CountIf(Rows(RowIndex), "?*") = 0 Then
Rows(RowIndex).Delete
End If
Next RowIndex
Application.ScreenUpdating = True
End Subhttps://stackoverflow.com/questions/57189568
复制相似问题