我的工作表中有两列。一个拥有名称,另一个拥有值。 “名称”列中的两个人的值= 0。我要排除这两个人的姓名和价值观。什么是VBA代码?
答案 0 :(得分:0)
Sub Init()
Range("A1").Value = "Names"
Range("A2").Value = "Petter"
Range("A3").Value = "Peter"
Range("A4").Value = "Peter2"
Range("A5").Value = "Petter3"
Range("A6").Value = "Petter4"
Range("B1").Value = "Values"
Range("B2").Value = 1
Range("B3").Value = 2
Range("B4").Value = 0
Range("B5").Value = 3
Range("B6").Value = 0
End Sub
Sub Delete_Values_If_0()
Dim lastRow As Long
Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:=0
lastRow = Range("A1").CurrentRegion.SpecialCells(xlCellTypeLastCell).Row
Debug.Print lastRow
Range("2:" & lastRow).Delete
Range("A1").CurrentRegion.AutoFilter
End Sub
Sub Hide_Values_If_0()
Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:="<>0", Operator:=xlAnd
End Sub
Sub FilterOff()
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
End If
End Sub