如何用VB删除excel中所有为空值的列
展开全部
'举个例子给你参考:
Sub 删除B列空格所在的行()
Application.ScreenUpdating = False
Dim a As long, b As long
Dim i As Long
b = Cells(65536, 1).End(xlUp).Row
On Error GoTo 100
For i = 1 To 256
a = Cells(65536, i).End(xlUp).Row
If b >= a Then
b = b
Else
b = a
End If
Next i
For i = b To 1 Step -1
If Cells(i, 2) = "" Then
Range(i & ":" & i).Delete shift:=xlUp
End If
Next i
100:
Application.ScreenUpdating = True
End Sub
Sub 删除B列空格所在的行()
Application.ScreenUpdating = False
Dim a As long, b As long
Dim i As Long
b = Cells(65536, 1).End(xlUp).Row
On Error GoTo 100
For i = 1 To 256
a = Cells(65536, i).End(xlUp).Row
If b >= a Then
b = b
Else
b = a
End If
Next i
For i = b To 1 Step -1
If Cells(i, 2) = "" Then
Range(i & ":" & i).Delete shift:=xlUp
End If
Next i
100:
Application.ScreenUpdating = True
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
希望对你有用。
里面用的判断有ISEMPTY,只要是有设置(格式)的单元格,不算空值。
Sub Macro2()
'
' Macro2 Macro
' 宏由 j 录制,时间: 2013/11/16
'
Dim i, ii
i = 1
Do
On Error Resume Next
If IsEmpty(Cells(1, i)) Then
If Cells(1, i).End(xlDown).Row = 65536 Then
Range(Cells(1, i), Cells(65536, i)).Delete
Else
i = i + 1
End If
Else
i = i + 1
End If
On Error GoTo 0
ii = ii + 1
Loop While ii < 257
End Sub
里面用的判断有ISEMPTY,只要是有设置(格式)的单元格,不算空值。
Sub Macro2()
'
' Macro2 Macro
' 宏由 j 录制,时间: 2013/11/16
'
Dim i, ii
i = 1
Do
On Error Resume Next
If IsEmpty(Cells(1, i)) Then
If Cells(1, i).End(xlDown).Row = 65536 Then
Range(Cells(1, i), Cells(65536, i)).Delete
Else
i = i + 1
End If
Else
i = i + 1
End If
On Error GoTo 0
ii = ii + 1
Loop While ii < 257
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |