Insert Search Bar in Excel Spreadsheet

Vsweeten

New Member
Joined
Sep 21, 2017
Messages
2
I am brand new to VBA so I need a very beginner type instruction set.
I have a spreadsheet only 1 worksheet, with all of the data in it.
I want to insert a search bar to be able to search the sheet by employee name and then have that employee's row of information show up at the top of the screen (or as the 2nd row of data).
I have tried just about all of the recommended VBA and macro's and nothing gives me what I want??
The data is all in columns A through F and there will be a lot of rows by the time it is done.
Can anyone please help.???
I have the command button and have assigned different macros to it in an attempt to get what I want and I get some things but not all of it....
Please help!!!
 
The reason the script did not work was because you never mentioned in your original post what column the name was in so I guessed at "A".

Try this:

Code:
Sub Search_Bar()
'Modified 9-22-17 4:19 PM EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row
Dim ans As String
ans = InputBox("Enter Name")
    For i = 3 To Lastrow
        If Cells(i, "B").Value = ans Then Rows(2).Value = Rows(i).Value
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Vsweeten,

Welcome to the Board.

If I understand your original request, you're asking for a way to enter a search term, then have the sheet display the result at the top of the window. If so, then you might consider the following...

Code:
Sub SearchBar_1023749()
Dim surch As String, found As Long
surch = InputBox(prompt:="Please enter a search term.", Title:="Search")
If surch <> "" Then
    On Error GoTo errHandler
    found = ActiveSheet.UsedRange.Find(What:=surch, After:=Cells(1, 1), LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
    ActiveWindow.ScrollRow = found
End If
errHandler:
    If Err.Number = 91 Then MsgBox "Search term not found."
End Sub

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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