填充单元时,我在运行几个单元格后会遇到运行时错误13
我正在尝试构建一个代码,该代码将帮助我根据另一个工作表中的2个不同表格的团队名称填充列表。
该代码实际上在前10个单元格中运行良好,然后我突然得到一个运行时错误13“ type Inbatch”,我无法确定它的代码是什么,
我的代码是,
Sub populateteam()
Dim wsAkasaka As Worksheet
Dim wsList As Worksheet
Set wsAkasaka = ThisWorkbook.Worksheets("Akasaka")
Set wsList = ThisWorkbook.Worksheets("All Japan")
Dim consultant As String
Dim manager As String
Dim team As String
consultant = wsAkasaka.Range("b" & (ActiveCell.Row)).Value
manager = Application.VLookup(consultant, wsList.Range("a13:c200"), 3, False)
team = Application.VLookup(manager, wsList.Range("E2:F11"), 2, False)
If IsEmpty(ActiveCell.Value) Then
ActiveCell.Value = team
ActiveCell.Offset(1, 0).Select
End If
End Sub
如果有人可以给我一个启示发生以及我该如何解决。
- 编辑 我忘了写我在“团队”声明上的错误, 我取出它并用“经理”运行了代码,但对此没有任何问题,但是当我要求团队时,我会收到错误
I am trying to build a code that will help me populate a list with the team names based on 2 different tables in another worksheet.
The code actually runs quite well for the first 10 cells, and then I suddenly get a Runtime error 13 "Type mismatch" and I cannot figure what is wrong with it
the code I have is
Sub populateteam()
Dim wsAkasaka As Worksheet
Dim wsList As Worksheet
Set wsAkasaka = ThisWorkbook.Worksheets("Akasaka")
Set wsList = ThisWorkbook.Worksheets("All Japan")
Dim consultant As String
Dim manager As String
Dim team As String
consultant = wsAkasaka.Range("b" & (ActiveCell.Row)).Value
manager = Application.VLookup(consultant, wsList.Range("a13:c200"), 3, False)
team = Application.VLookup(manager, wsList.Range("E2:F11"), 2, False)
If IsEmpty(ActiveCell.Value) Then
ActiveCell.Value = team
ActiveCell.Offset(1, 0).Select
End If
End Sub
If anyone could give me a light for why this is happening and how could I fix it.
- Edit
I forgot to write I get the error on the "team" declaration,
I took it out and ran the code populating with "manager" and had no problem with it, but when I ask for the team I get the error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您将变量定义为字符串,并且如果您的
vlookup
返回错误(如果vlookup
找不到任何东西),则错误不能施加到字符串
中,您会得到不匹配错误。因此,我建议以下内容:
The issue is that you define your variables
As String
and if yourVLookup
returns an error (in caseVLookup
doesn't find anything), this error cannot be cast into aString
and you get a Mismatch Error.Therefore I recommend the following: