excel - 使用用户表单进行 Vlookup
问题描述
我正在尝试使用 3 个文本框配置 Userform 研究,但我无法使其工作,也不知道为什么。
这是我的代码:
Private Sub TextBox1_AfterUpdate()
On Error GoTo 1
If WorksheetFunction.CountIf(Sheets("Feuil1").Range("A:A"), Me.TextBox1.Value) = 0 Then
MsgBox "introuvable"
End If
With Me
.TextBox2 = Application.WorksheetFunction.VLookup(CLng(Me.TextBox1), Feuil1.Range("A:E"), 2, 0)
End With
1
End Sub
希望得到你的帮助
谢谢
解决方案
删除WorksheetFunction
然后如果没有匹配则不会出现运行时错误:
Private Sub TextBox1_AfterUpdate()
Dim r
r = Application.VLookup(CLng(Me.TextBox1), Feuil1.Range("A:E"), 2, False)
Me.TextBox2 = IIf(IsError(r),"Introuvable", r)
End Sub
推荐阅读
- r - 如何在栅格堆栈之间执行操作并对 R 中的所有文件夹重复操作?
- ruby-on-rails - Brakeman 没有使用 --skip-files 参数跳过 Gemfile.lock
- php - 使用 while 循环 SQL 更新多个数据
- c# - 从 IIS 中托管的 asp.net 核心应用程序的错误中获取完整的堆栈跟踪
- c - C中的代码排序错误
- c# - 用于字段单位转换的 C# 隐式获取
- php - 加入两个表以列出用户的所有对话
- vba - Workbook.Activate 方法行为异常
- java - JSON时间格式转Android时间格式
- python - Keras Sequential 模型的多个嵌入层