![](/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.