关于Excel中的行删除
在Excel中对于空行的删除有人已经讨论过:
Application.ScreenUpdating = False
j = Range("A4000").End(xlUp).Row
i = 1
For A = 1 To j
Rows(i).Select
If Application.CountA(Selection.Rows) = 0 Then
Selection.Rows.Delete
i = i - 1
End If
i = i + 1
Next A
Application.ScreenUpdating = True
可是如果我要删除的行不是全为空,而是通过每行的第一列的值来判断怎么办?
Rogersfeng
試試
Sub test()
Dim i As Long, j As Integer
dim pt as range
Application.ScreenUpdating = False
i = ActiveSheet.Range("a65536").End(xlUp).Row
For j = i To 1 Step -1
Set pt = ActiveSheet.Cells(j, 1)
If pt = "" Then pt.EntireRow.Delete
Next
Application.ScreenUpdating = True
End Sub
这里提示错误13:“类型不匹配”
我想dim pt as range,那么If pt = "" Then pt.EntireRow.Delete这句话应该是
if pt的值=“” Then pt.EntireRow.Delete!
可是我试了If pt.vaule = "" Then pt.EntireRow.Delete,它还是提示:“类型不匹配”
将If pt = "" Then pt.EntireRow.Delete改为If Application.CountA(pt) = 0 Then pt.EntireRow.Delete即可以了