Re: [算表] 自訂表單的資料回傳(VBA)

看板Office作者 (windknife18)時間16年前 (2009/09/02 10:11), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
應該是使用 文字或數字的關係,一種是將所以的資料變成文字,另一種如下 Private Sub CommandButton1_Click() Dim i As Integer Dim s As Variant Dim rg As String Dim res1 As Variant Set rg = Range("A1:B10") s = TextBox1.Value If IsNumeric(s) Then res1 = Application.VLookup(Val(s), rg, 2, 0) Else res1 = Application.VLookup(s, rg, 2, 0) End If TextBox2.Value = IIf(IsError(res1), "", res1) End Sub ※ 引述《itat2007 (Black Day)》之銘言: : 軟體:excel : 版本:2003 : 小弟想問一個簡單的問題,在自訂表單中,TextBox1 輸入一個流水號 : TextBox2得到相對的回傳資料,以下是簡單的範例 : 在sheet1中輸入簡單資料 : A B : 張三 72 : 李四 86 : 周七 93 : 馮九 78 : 馬六 89 : 1122 5533 : 5566 2214 : 7788 2211 : 在UserForm1中輸入 : Private Sub CommandButton1_Click() : Dim i As Integer : Dim s As String : Dim rg As Range : Dim res1 As Variant : Set rg = Range("A1:B" & [B65536].End(xlUp).Row) : s = TextBox1.Value : res1 = Application.VLookup(s, rg, 2, 0) : TextBox2.Value = IIf(IsError(res1), "", res1) : End Sub : 當TextBox1輸入 張三 時 TextBox2 能夠得到72 : 但是當輸入 1122 時,無法得到5533 : 不知道要如何宣告才能得到想要的值, : 還有是否有更快的方法來做到當TextBox1輸入時,TextBox2~10能很快的得到相對應的值 : 麻煩各位大大幫忙 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.131.84.1
文章代碼(AID): #1AdTH1pi (Office)
文章代碼(AID): #1AdTH1pi (Office)