PDA

View Full Version : Excel Vba textbox userform Vlookup give missmatch error



Jee Moon
09-21-2015, 03:53 AM
Hi,

I am new in forum i have problem in excel vba userform.

here i excel vba userform i have

1.Two text box

2. I display excel sheet data into excel vba userform textbox


3. when i enter the excel sheet 1st row value in textbox1 than textbox2 show the 2nd row value through vlookup function but vlookup give mistmatch run time error 13.

Here i inser code


Private Sub TextBox1_Change()
'Check to see if value exists
If WorksheetFunction.CountIf(Sheet1.Range("A:B"), Me.TextBox1.Value) = 0 Then
MsgBox "This is an incorrect ID"
Me.TextBox1.Value = ""
Exit Sub
End If
'Lookup values based on first control
With Me
.TextBox2.Value = Application.WorksheetFunction.VLookup(CLng(Me.TextBox1.Value), Sheet1.Range("A:B"), 2, True)
End With
End Sub


Please check where i do mistake

SamT
09-21-2015, 08:04 AM
Change Event occurs on every character entered. Use AfterUpdate.

Private Sub TextBox1_AfterUpdate()
Dim Found As Range
With Me
Set Found = ThisWorkbook.Sheets("Sheet1").Range("A:A").Find(.TextBox1.Value)
If Found Is Nothing Then
MsgBox "This is an incorrect ID"
.TextBox1.Value = ""
.TextBox1.SetFocus
Exit Sub
End If

.Textbox2.Value = Found.Value
End With
End Sub

Jee Moon
09-22-2015, 04:39 AM
Please,

Please u check my attached sheet in which it show information, but why it give the mismatch error Run time "13".

Please solve this problem.