Excel 根据用户输入VBA检查单元格范围
我试图对照用户输入的值检查一小部分值。该查询在该范围内循环,但在应该查询的时候,它从不点击ActiveCell.EntireRow.Clear行。我的代码在下面,有什么想法吗Excel 根据用户输入VBA检查单元格范围,excel,user-input,vba,Excel,User Input,Vba,我试图对照用户输入的值检查一小部分值。该查询在该范围内循环,但在应该查询的时候,它从不点击ActiveCell.EntireRow.Clear行。我的代码在下面,有什么想法吗 Private Sub CommandButton3_Click() Dim iLastRow As Long Dim i As Long Dim myValue2 As String myValue2 = InputBox("Enter Last Name:") With ActiveSheet iLastR
Private Sub CommandButton3_Click()
Dim iLastRow As Long
Dim i As Long
Dim myValue2 As String
myValue2 = InputBox("Enter Last Name:")
With ActiveSheet
iLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For i = 33 To iLastRow
If ActiveCell.Value = myValue2 Then
ActiveCell.EntireRow.Clear
Else
End If
Next i
End With
End Sub
您不需要ActiveCell:
Private Sub CommandButton3_Click()
Dim iLastRow As Long
Dim i As Long
Dim myValue2 As String
myValue2 = InputBox("Enter Last Name:")
With ActiveSheet
iLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For i = 33 To iLastRow
If Cells(i, "B").Value = myValue2 Then
Cells(i, "B").EntireRow.Clear
End If
Next i
End With
End Sub