代码:
Sub 删除()
Dim n, i
n = [a1].End(xlDown)
For i = 2 To n
If Range("A" & i) = [d2] Then Range("A" & i).Delete
Next i
End Sub
效果如下图所示:
Dim Rng As Range
With ActiveSheet
For Each Rng In .Range(.Cells(2, 1), .Cells(.Cells.Rows, 1).End(xlUp)) '从 A2 到 A列最后一行开始查找
If Rng.Value = .Cells(2, 4) Then '如果等于 D2 单元格的内容
.Range(.Cells(Rng.Row, 2), .Cells(Rng.Row, 3)).Clear '清除同行的 B、C 两列单元格中的数据
End If
Next Rng
End With
请楼主把下面的代码复制到你的 Button1_Click 事件中:
Dim Rng As Range
With ActiveSheet
For Each Rng In .Range(.Cells(2, 1), .Cells(.Cells.Rows, 1).End(xlUp)) '从 A2 到 A列最后一行开始查找
If Rng.Value = .Cells(2, 4) Then '如果等于 D2 单元格的内容
.Range(.Cells(Rng.Row, 2), .Cells(Rng.Row, 3)).Clear '清除同行的 B、C 两列单元格中的数据
End If
Next Rng
End With
一键delete全部搞定,或是鼠标右键清除内容将其删除掉。