Problem filling textBox

Andre

New Member
Joined
Sep 7, 2002
Messages
22
Hi everybody,

I've got a problem that i'cant fix. Sure need some help.

On a form i've got a certain amount of textboxes. When I fill in a number in textbox1 and the number is allready in column A, I want it to fill textbox2 with the data that is in column B (same row). The procedure starts when i exit textbox1.

The code i've got sofar is this:

Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Sheets("Data1").Select
Range("A2").Select
Selection.End(xlDown).Select

Do Until ActiveCell.Value = "number" '(is the header of column A)

    If ActiveCell.Value = TextBox1.Value Then
    TextBox2.Value = ActiveCell.Offset(0, 1).Value
    Else
    ActiveCell.Offset(-1, 0).Select
    End If

Loop

End Sub

With this code nothing is put in textbox2 while the value i put in textbox1 is certainly in column A.


As you can see the loop works from the bottom of the column to the top. This is because the newest data is in the last cell of the range.

I hope anybody can help me out.

Greetings Andre
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Andre

Try
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
 TextBox2.Value = ""
 Set findit = Sheets("data1").Range("a:a").Find(what:=Val(TextBox1.Value))
 If Not findit Is Nothing Then TextBox2.Value = findit.Offset(0, 1).Value

End Sub


Tony
 
Upvote 0

Forum statistics

Threads
1,214,556
Messages
6,120,190
Members
448,949
Latest member
keycalinc

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top