第1个回答 2011-09-15
creenUpdating = False
For i = Sheet2.UsedRange.Rows.Count To 1 Step -1
If Application.WorksheetFunction.Sum(Rows(i)) = 0 Then Rows(i).Delete
Next
Application.ScreenUpdating = True
End Sub
你的空白行是就'J列有空白 其他都有数据么这代码是把表里面有空的行都删除掉 你要是就J列有空可以用 要是其他列也有空 可以用过滤的办法删除掉~~
第2中情况的代码我再找找看
找到了
Sub 删除所选区域空行()
'Deletes the entire row within the selection if the ENTIRE row contains no data.
'删除所选区域内空行
'We use Long in case they have over 32,767 rows selected.'我们用长整型以免出错
Dim i As Long
'We turn off calculation and screenupdating to speed up the macro. 关掉自动重算和屏幕刷新以提高速度
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
'We work backwards because we are deleting rows. 由于要删除行,所以要FOR NEXT要倒着来
For i = Selection.Rows.Count To 1 Step -1
'for i=ActiveSheet.UsedRange.Rows.Count to 1 step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
这代码用的时候必要选择整列要不运算慢 你可以选J1:J100然后运行代码