Search loop

Mileshigh

Board Regular
Joined
Oct 1, 2008
Messages
54
I am trying to make a very simple search and cant seem to get it to work

Basicaly I have a txtbox "txtsearch" that a user will type in an order number (this is in column C) and click cmdsearch button. Then the search would find the match and make the active cell the corresponding cell for that row in Column A.

Column A Column C
Sandy 89b40

The search would find the "89b40" number and make the active cell selected "sandy"

Thanks any help would be great
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try like this

Code:
Private Sub CommandButton1_Click()
Dim Found As Range
Set Found = Columns("C").Find(what:=TextBox1.Text, LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then Found.Offset(, -2).Select
Unload Me
End Sub
 
Upvote 0
Something along the lines of

Dim c As Range, rng
Set rng = Range("c1:c1000")
myorder = Application.InputBox("Enter an Order Number")
For Each c In rng
If c.Value = myorder Then
c.Offset(0, -2).Select
End If
Next c
 
Upvote 0
Ok so the 1st way works but doesnt report to the user if there are no matches found but rather will just stay on the same cell...which is fine but i want the user to know...

The second method locks up excel everytime
 
Upvote 0
Try

Code:
Private Sub CommandButton1_Click()
Dim Found As Range
Set Found = Columns("C").Find(what:=TextBox1.Text, LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then
    Found.Offset(, -2).Select
Else
    MsgBox TextBox1.Text & " not found", vbInformation
End If
Unload Me
End Sub
 
Upvote 0
Yea thats what i tried first but I keep getting a "else without If" error and nothing i seem to do will work
 
Upvote 0
Very weird...so i commented out what I typed in and pasted your post...they are the same and yet i works! Thanks for helping me out
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,652
Members
452,934
Latest member
mm1t1

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