求教excel中使用VB代码删除每个sheet中某个列中值为特定值的一整行
excel中使用VB代码删除每个sheet中某个列(比如columnname是“b”)的这一列如果某一行值为0,那就删除一整行,我写的代码如下,但是只能删除sheet1中...
excel中使用VB代码删除每个sheet中某个列(比如column name 是 “b”)的这一列如果某一行值为0,那就删除一整行,我写的代码如下,但是只能删除sheet1中的,sheet中的还是没有删除掉
Sub wfdele()
比如删除column name 是b的那一列中如果出现0, 则删除这一整行。我写的代码如下,但是只删除了sheet1中的,sheet2中没有反应。求大神指教
Sub wfdele()
Dim sh As Worksheet
Dim c As Long
Dim r As Long
Dim LastRow As Integer
Dim Lastcolumn As Integer
For Each sh In Worksheets
Lastcolumn = sh.[IV1].End(xlToLeft).Column
LastRow = sh.[a65536].End(xlUp).Row
For c = 1 To Lastcolumn
If sh.Cells(1, c).Value = "b" Then
For r = LastRow To 1 Step -1
If sh.Cells(r, c).Value = "0" Then
Range(r & ":" & r).Delete shift:=xlUp
End If
Next
End If
Next
Next
End Sub
已经解决了,但是居然没有人回答也不能删除(删除要扣除金币,我没有那么多金币( ⊙ o ⊙ )。 展开
Sub wfdele()
比如删除column name 是b的那一列中如果出现0, 则删除这一整行。我写的代码如下,但是只删除了sheet1中的,sheet2中没有反应。求大神指教
Sub wfdele()
Dim sh As Worksheet
Dim c As Long
Dim r As Long
Dim LastRow As Integer
Dim Lastcolumn As Integer
For Each sh In Worksheets
Lastcolumn = sh.[IV1].End(xlToLeft).Column
LastRow = sh.[a65536].End(xlUp).Row
For c = 1 To Lastcolumn
If sh.Cells(1, c).Value = "b" Then
For r = LastRow To 1 Step -1
If sh.Cells(r, c).Value = "0" Then
Range(r & ":" & r).Delete shift:=xlUp
End If
Next
End If
Next
Next
End Sub
已经解决了,但是居然没有人回答也不能删除(删除要扣除金币,我没有那么多金币( ⊙ o ⊙ )。 展开
1个回答
展开全部
为了验证代码是否获得除了sheet1表以外的其它表:
Sub wfdele()
Dim sh As Worksheet
Dim c As Long
Dim r As Long
Dim LastRow As Integer
Dim Lastcolumn As Integer
For Each sh In Worksheets
debug.print sh.name '增加的代码
Lastcolumn = sh.[IV1].End(xlToLeft).Column
LastRow = sh.[a65536].End(xlUp).Row
For c = 1 To Lastcolumn
If sh.Cells(1, c).Value = "b" Then
For r = LastRow To 1 Step -1
If sh.Cells(r, c).Value = "0" Then
Range(r & ":" & r).Delete shift:=xlUp
End If
Next
End If
Next
Next
End Sub
Sub wfdele()
Dim sh As Worksheet
Dim c As Long
Dim r As Long
Dim LastRow As Integer
Dim Lastcolumn As Integer
For Each sh In Worksheets
debug.print sh.name '增加的代码
Lastcolumn = sh.[IV1].End(xlToLeft).Column
LastRow = sh.[a65536].End(xlUp).Row
For c = 1 To Lastcolumn
If sh.Cells(1, c).Value = "b" Then
For r = LastRow To 1 Step -1
If sh.Cells(r, c).Value = "0" Then
Range(r & ":" & r).Delete shift:=xlUp
End If
Next
End If
Next
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询