![](/img/trans.png)
[英]Use VLOOKUP but detach the value from the lookup once it is in the cell/looked up
[英]How to return the value of vlookup in same cell in which the value to be looked up is entered?
我想在输入要查找的值的同一单元格中返回vlookup的结果。 图1显示了要查找的值
图1
我希望在按Enter时将A1中的值更改为t001的vlookup值,如图2所示
图2
在sheet2中存在查找表t001 trew t002 rty
按照我编写的代码,但无法正常工作; 请在这方面帮助我
Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:A114")) Is Nothing Then
If WorksheetFunction.IsNumber(Target.Value) Then
Application.EnableEvents = False
Table2 = Sheet2.Range("C2:D3")
Target.Value = Application.WorksheetFunction.VLookup(Target.Value, Table2, 2, False)
Application.EnableEvents = True
End If
End If
End Sub
通过使用
If WorksheetFunction.IsNumber(Target.Value) Then
...
End If
如果目标值不是数字,请确保不会执行'if'子句的内部。 例如具有Table2
abc ¦ not working
-----------------
123 ¦ working
键入“ abc”后没有任何反应,键入123后数字消失并且出现“正在工作”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.