Excel如何利用VBA的宏功能删除空行和指定字符的行?

2025-01-01 00:19:36
推荐回答(2个)
回答1:

没看明白,
总条件是:只针对A列的数据,不要删B列之后的其他列。
最后又说:但是如果A2只是a,删除整行。
这是矛盾的
还有,没说明白,是删除数据,还是删除单元格?
Public Sub RowDele()
Dim H As Long, i As Long, a, b
H = Range("A65536").End(xlUp).Row
a = Array("A", "a", "@", "#", "") '可以在这里增加其他字符
b = "|" & Join(a, "|") & "|"
For i = H To 1 Step -1
If InStr(b, "|" & Cells(i, 1) & "|") Then
Rows(i).Delete
End If
Next
End Sub

回答2:

这个用vba来处理
sub demon()
dim x as long
dim r as long
r=cells(rows.count, 1).end(xlup).row
for x = r to 1
if application.counta(rows(x))=0 then
rows(x).delete
elseif application.countif(rows(x), "A")>0 then
rows(x). delete
end if
next x

end sub