ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 806|回复: 2

求助大神帮忙看看,VBA运行代码时出现错误'13'类型不匹配,错误的地方如下红色字体...

[复制链接]

TA的精华主题

TA的得分主题

发表于 2018-4-15 13:36 | 显示全部楼层 |阅读模式

Private Sub Query_Click()
Worksheets("在职人员").Select
Dim i As Integer
i = 0
Dim Num As Long
Dim str As String
Num = Worksheets("在职人员").Range("D1048576").End(xlUp).Row
str = InputBox("请输入需要查询的姓名")
Range("AS2").FormulaR1C1 = "=countif(DataArea,""" & str & """)"
Dim MyArray(6, 10) As String
             MyArray(0, 0) = "序号"
             MyArray(1, 0) = "员工编号"
             MyArray(2, 0) = "姓名"
             MyArray(3, 0) = "性别"
             MyArray(4, 0) = "现职位"
             MyArray(5, 0) = "现部门"
If Range("AS2").Value > 1 Then    (这是出现错误的地方)
     员工信息管理.Height = 447
     w_UserList.Visible = True
     With Worksheets(1).Range("DataArea")
     Set c = .Find(str, LookIn:=xlValues)
     If Not c Is Nothing Then
          firstAddress = c.Address
          Do
             i = i + 1
             MyArray(0, i) = Cells(c.Row, 1)
             MyArray(1, i) = Cells(c.Row, 3)
             MyArray(2, i) = Cells(c.Row, 4)
             MyArray(3, i) = Cells(c.Row, 6)
             MyArray(4, i) = Cells(c.Row, 33)
             MyArray(5, i) = Cells(c.Row, 32)
             Set c = .FindNext(c)
         Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    End With
    w_UserList.Column() = MyArray
    Exit Sub
End If
With Worksheets(1).Range("DataArea")
     Set c = .Find(str, LookIn:=xlValues)
     If Not c Is Nothing Then
         firstAddress = c.Address
         Do
w_b_WorkerID.Text = Cells(c.Row, 3)
w_b_WorkerName.Text = Cells(c.Row, 4)
w_b_BirthDay.Text = Cells(c.Row, 5)
w_b_Sex.Text = Cells(c.Row, 6)
w_b_Marry.Text = Cells(c.Row, 7)
w_b_Stu.Text = Cells(c.Row, 8)
w_b_Chen.Text = Cells(c.Row, 9)
w_b_StuTech.Text = Cells(c.Row, 10)
w_b_School.Text = Cells(c.Row, 11)
w_b_Mobel.Text = Cells(c.Row, 12)
w_b_Number.Text = Cells(c.Row, 13)
w_b_Address.Text = Cells(c.Row, 14)
w_b_NowAddress.Text = Cells(c.Row, 15)
w_b_HomeTelphone.Text = Cells(c.Row, 16)
w_b_WorkTime.Text = Cells(c.Row, 17)
w_b_FName.Text = Cells(c.Row, 18)
w_b_FWork.Text = Cells(c.Row, 19)
w_b_Type.Text = Cells(c.Row, 20)
w_b_HouseCarID.Text = Cells(c.Row, 21)
w_b_CarID.Text = Cells(c.Row, 22)
w_b_TechBook.Text = Cells(c.Row, 23)
w_b_TechTime.Text = Cells(c.Row, 24)
w_w_Time.Text = Cells(c.Row, 25)
w_w_WorkTime.Text = Cells(c.Row, 26)
w_w_WorkStu.Text = Cells(c.Row, 27)
w_w_WorkingTime.Text = Cells(c.Row, 28)
w_w_Dep.Text = Cells(c.Row, 32)
w_w_Worker.Text = Cells(c.Row, 33)
w_w_DepS.Text = Cells(c.Row, 34)
w_w_WorkID.Text = Cells(c.Row, 35)
w_b_Image.Picture = LoadPicture("C:\Users\Administrator\Desktop\素材图片\" & Cells(c.Row, 2))
          cs = c.Row
          Set c = .FindNext(c)
       Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    End With
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2018-4-15 16:18 | 显示全部楼层
查询按钮代码有问题

Book2 (自动保存的).zip

39.44 KB, 下载次数: 6

TA的精华主题

TA的得分主题

发表于 2018-4-30 11:09 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
自定义名称错误了,不存在了,修改下=COUNTIF(DataArea,"")
DataArea日期区域的自定义名称被删除了,自己补充完整就行了
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-25 05:09 , Processed in 0.030762 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表