注册 登录
编程论坛 Excel/VBA论坛

运行时错误“91”,对象变量或with块变量未设置

leij 发布于 2020-06-08 10:26, 1968 次点击
大佬们求解:调试的时候 Set rngNum = rngNum.EntireColumn.Find(strS)显示”运行时错误“91”,对象变量或with块变量未设置“

代码如下:
Option Explicit
Public frmStatus As String
Public rowNum As Integer

Sub 查询员工信息()
     Dim strS As String
     Dim intRow As Integer
     Dim rngNum As Range, rngName As Range

     strS = InputBox("请输入员工的编号或姓名", "员工查询")
     If strS <> "" Then
         Set rngNum = Sheets("员工个人信息表").UsedRange.Find("编号")
         Set rngName = Sheets("员工个人信息表").UsedRange.Find("姓名")
         
         If rngNum Is Nothing Or rngName Is Nothing Then
              MsgBox "员工个人信息表错误,无法进行操作"
              Exit Sub
         End If
         
         intRow = -1
         Set rngNum = rngNum.EntireColumn.Find(strS)
         
         If rngNum Is Nothing Then
             Set rngName = rngName.EntireColumn.Find(strS)
             If Not (rngName Is Nothing) Then
                 intRow = rngName.Row
             End If
         Else
             intRow = rngNum.Row
         End If
            
         If intRow > 0 Then
            frmStatus = "查询"
            rowNum = intRow
            Load UserForm1
            UserForm1.Show
         Else
            MsgBox "没找到与“" & strS & "”相关数据!", , "提示"
         End If
    End If
   
End Sub
2 回复
#2
厨师王德榜2020-06-08 10:40
在我的电脑上运行无问题,不过由于我的电脑上无userForm1,所以,
'            Load UserForm1
'            UserForm1.Show
这两句我是屏蔽了的.
#3
leij2020-06-08 10:54
回复 2楼 厨师王德榜
我又运行了一遍,
            'Load UserForm1
出问题,弹出提示:
运行时错误'424'
要求对象
1