我正在尝试根据用户输入的值检查一小部分值。查询遍历范围,但它永远不会在应该命中 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
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