根据用户输入VBA检查一系列单元格

时间:2014-11-26 16:08:16

标签: excel-vba user-input vba excel

我正在尝试针对用户输入的值检查一小部分值。查询循环遍历范围,但它永远不会遇到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

1 个答案:

答案 0 :(得分:0)

您不需要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
相关问题