vba textbox輸入比對值顯示於label

2015-07-22 5:58 pm
請問各位大大,
當 textbox輸入值按下enter後
想要顯示vlookup比對後的資料在label中
附上程式碼, 不知是那裡寫錯了,為何完全沒反映, 請大大指教, 謝謝

Private Sub TextBox67_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Label3.Caption = "" Then
Label3.Caption = Application.WorksheetFunction.VLookup(TextBox67.Text, Sheet2.Range("a2:b10"), 2, False)

End If
lable3 = ""

End Sub

回答 (3)

2015-07-23 3:37 am
✔ 最佳答案
參考!參考!

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim t As Variant
If KeyCode = 13 Then
Label1 = ""
Set Rg = Sheets(2).[A:B]
Xg = TextBox1
t = Application.VLookup(Xg, Rg, 2, False)
If Not IsError(t) Then
Label1 = t
Else
Label1 = "查無"
End If
TextBox1 = ""
End If
End Sub
2015-07-23 5:28 am
謝謝cascade 大的指正...
2015-07-23 3:29 am
第3句改成:Label3.Caption = Application.VLookup(TextBox67.Text, Sheets("Sheet2").Range("a2:b10"), 2, False)

第5句改成:Label3 = ""
試試


收錄日期: 2021-04-23 23:53:22
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20150722000016KK02681

檢視 Wayback Machine 備份