我正在编写excel vba并遇到此问题Error 91 - Object variable or with block variable not set
。我似乎无法找到代码问题的位置。这是我的代码:
Private Sub cmdUpdate_Click()
Dim findValue As Range
Dim cNum As Integer
Dim DataSH As Worksheet
On Error GoTo errHandler:
Application.ScreenUpdating = False
Set DataSH = Sheet1
lstStudents.RowSource = ""
Set findValue = DataSH.Range("A:A"). _
Find(What:=Me.txtStudNo2.Value, LookIn:=xlValues, LookAt:=xlWhole)
findValue = txtStudNo2.Value
findValue.Offset(0, 1) = txtStudNo2.Value
findValue.Offset(0, 2) = txtName.Value
findValue.Offset(0, 3) = cboCollege2.Value
findValue.Offset(0, 4) = cboCourse2.Value
findValue.Offset(0, 5) = txtMobNo2.Value
Unprotect_All
DataSH.Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Data!$L$1:$L$2"), CopyToRange:=Range("Data!$M$1:$Q$1"), _
Unique:=False
If DataSH.Range("M2").Value = "" Then
lstStudents.RowSource = ""
Else
lstStudents.RowSource = DataSH.Range("outdata").Address(external:=True)
End If
Sheet2.Select
Protect_All
On Error GoTo 0
Exit Sub
errHandler:
Protect_All
MsgBox "An Error occured " & vbCrLf & _
"The error number is: " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & "Please notify the administrator"
End Sub