Search in workbook and get row number

obaid_457

New Member
Joined
Jul 27, 2017
Messages
6
this is my first post here an i am very beginner of excel vba

my question is

i have a userform with
textbox1
textbox2
textbox3
and CommandButton1

in my excel sheet in first colam i have numbers
if the data i type in textbox1 in cell "A" it shows the result of Cell "b" in textbox2. that is ok i can
with this code

Code:
Private Sub CommandButton1_Click()TextBox2.Text = Clear
TextBox3.Text = Clear
Dim apple As Long
Dim test As Long
apple = Sheets("sheet1").Range("a" & Rows.Count).End(xlUp).Row
For test = 1 To apple
If Sheets("sheet1").Cells(test, 1).Text = TextBox1.Value Then
TextBox2.Text = Sheets("sheet1").Cells(test, 2)
End If
Next test
End Sub


i want that it show the row number in TextBox3
is that Possible?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I believe the line bolded and underlined below will give you what you want

Code:
Private Sub CommandButton1_Click()TextBox2.Text = Clear
TextBox3.Text = Clear
Dim apple As Long
Dim test As Long
apple = Sheets("sheet1").Range("a" & Rows.Count).End(xlUp).Row
For test = 1 To apple
    If Sheets("sheet1").Cells(test, 1).Text = TextBox1.Value Then
    TextBox2.Text = Sheets("sheet1").Cells(test, 2)
    [U][B]textBox3.Text = test[/B][/U]
End If
Next test
End Sub
 
Upvote 0
It works Brother
Brother You are not in Front of Me
otherwise i will hug you for that

many many many thanks Brorther
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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