如果包含两个输入值,请删除行

时间:2015-08-24 19:05:22

标签: vba for-loop delete-row inputbox

我需要在列表中搜索您通过弹出窗口定义的两个输入值。输入工作但for / if循环不会开始,我很难过。任何帮助表示赞赏。

以下代码:

Dim dieNumber As Variant
Dim serial As Variant
Dim i As Long


Set rng = Range("A3:J1000") 'range of master list

dieNumber = InputBox("Enter Die Number to Delete")
serial = InputBox("Enter Serial Number of Die")

With ActiveSheet

For i = 1000 To Rows.Count

    If (Row.Cells(2).Value = dieNumber And Row.Cells(3).Value = serial) Then

        EntireRow.Delete

    End If

Next i

End With

2 个答案:

答案 0 :(得分:0)

这样可行。

Dim dieNumber As Variant
Dim serial As Variant
Dim i As Long
Dim ws As Excel.Worksheet
Set ws = Application.ActiveSheet

Set rng = ws.Range("A3:J1000") 'range of master list

dieNumber = InputBox("Enter Die Number to Delete")
serial = InputBox("Enter Serial Number of Die")

For i = 1000 To ActiveSheet.UsedRange.Rows.count
    If ws.Range("B", & i).Value = dieNumber And ws.Range("C", & i).Value = serial Then
        ws.Range("B", & i).EntireRow.Delete
    End If
Next i

但是,如果您尝试删除范围中的项目,则需要将for循环更改为从3开始。

For i = 3 To

答案 1 :(得分:0)

For Rand = 3 To ActiveSheet.UsedRange.Rows.Count

If Cells(Rand, 2).Value = DieNumber And Cells(Rand, 3).Value = Serial Then
        Rows(Rand).EntireRow.Delete
End If

这最终为我工作。谢谢你的帮助MatthewD