当我尝试设置一些代码以根据表列中的特定单词/数字删除表中的行数时,出现错误
Run-time error '1004' Method 'Range' of object'_Global' failed.
我使用的代码几乎与另一个工作簿中的以下代码相同,没有任何问题。我更改了工作表编号,表名称,列名称和文本框名称,以匹配新的工作簿信息。
Dim intLastRow As Integer
Dim strDelete As String
Dim rngFindID As Range
Dim intAnswer As Integer
Sheet1.Activate
Set rngFindID = Range("tblMaster[Job #]").Find(txtJobid.Value, LookIn:=LookIn = xlValues, lookat:=xlWhole)
If rngFindID Is Nothing Then
MsgBox "Job # doesn't exist in records."
Else
intAnswer = MsgBox("Job # found. Delete?", vbYesNo + vbQuestion, "Delete Record")
If intAnswer = yes Then
strDelete = txtJobid.Value
intLastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = intLastRow To 1 Step -1
If Cells(i, 1) = strDelete Then Rows(i & ":" & i).EntireRow.Delete
Next i
Else
'do nothing
End If
End If
我希望此代码根据Job#列中单元格中的值删除某些行。线
Set rngFindID = Range("tblMaster[Job #]").Find(txtJobid.Value, LookIn:=LookIn = xlValues, lookat:=xlWhole)
以前面提到的错误代码突出显示。
这是我第一次在该论坛上发帖。请让我知道是否需要更多信息。