错误91;对象变量或未设置块变量

时间:2018-10-09 04:11:41

标签: excel vba excel-vba

我的问题是,为什么每当我尝试调试该错误时都是Runtime error 91;未设置对象变量或带块变量。我尝试查看另一个示例,并尝试在论坛中找到解决方案,但仍然找不到。

我可以知道这是什么错误吗?希望有人可以向我解释。

谢谢。

Private Sub cmdDelete_Click()

Dim findvalue As Range
Dim cDelete As VbMsgBoxResult
Dim cNum As Integer
Dim DataSH As Worksheet
Set DataSH = Sheet1
Dim x As Integer
Dim Addme As Range

On Error GoTo errHandler:

Application.ScreenUpdating = False

If Emp1.Value = "" Or Emp2.Value = "" Then
    MsgBox "There is not data to delete"
Exit Sub
End If

cDelete = MsgBox("Are you sure that you want to delete this training", _
vbYesNo + vbDefaultButton2, "Are you sure?")
If cDelete = vbYes Then

Set findvalue = DataSH.Range("B:B").Find(What:=Me.Emp1.Value, _
LookIn:=xlValues, LookAt:=xlWhole)

Set Addme = Sheet24.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

findvalue.Range("A1:H1").Copy
Addme.PasteSpecial (xlPasteValues)

findvalue.EntireRow.Delete
End If

cNum = 7
For x = 1 To cNum
Me.Controls("Emp" & x).Value = ""
Next

DataSH.Range("B8").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Data!$L$8:$L$9"), CopyToRange:=Range("Data!$N$8:$T$8"), _
Unique:=False

If DataSH.Range("N9").Value = "" Then
    lstEmployee.RowSource = ""
Else

lstEmployee.RowSource = DataSH.Range("outdata").Address(external:=True)
End If

DataSH.Select
With DataSH
.Range("B9:H10000").Sort Key1:=Range("C9"), Order1:=xlAscending, Header:=xlGuess
End With

Sheet2.Select

On Error GoTo 0
Exit Sub

errHandler:

MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " & _
Err.Number & vbCrLf & Err.Description & vbCrLf & "Please notify the administrator"

End Sub

0 个答案:

没有答案