In Need of a Custom Search Box

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
138
Hi Everyone,

What would be the best way to use a cell in a worksheet as a search box to search column E:F for a UPC?

I would want to have that search box in Row 1 and freeze that row so its always visible.
The search box would be populated by a scan of a UPC. Once the UPC is found in E:F, I would want the cursor
to move to the cell which was found.

I realize this is much like the built in search function but the dialog box is always in the way so either have to
move it or close it.

Thanks so much.
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,446
Office Version
  1. 2013
Platform
  1. Windows
You can try this change event code and see if it is what you want. The code should be installed in the sheet code module and it will run when there is a change is made in row 1.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim fn As Range
If Not Intersect(Target, Rows(1)) Is Nothing Then
    If Target <> "" Then
        Set fn = Intersect(ActiveSheet.UsedRange.Offset(1), ActiveSheet.Range("E:F")).Find(Target.Value, , xlValues)
        fn.Select
    End If
End If
End Sub
 

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
138
Hi JLGWhiz,

I am getting an error in the code at "fn.Select".

"Run-time error '91':
Object variable or With block variable not set"

FYI we will be using Cell K1 as the search.


Thank you!

 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,446
Office Version
  1. 2013
Platform
  1. Windows
If it did not find the value then it would not set the fn variable. The code below is modified to accomodate that condition and avoid the error message.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim fn As Range
If Not Intersect(Target, Rows(1)) Is Nothing Then
    If Target <> "" Then
        Set fn = Intersect(ActiveSheet.UsedRange.Offset(1), ActiveSheet.Range("E:F")).Find(Target.Value, , xlValues)
            If Not fn Is Nothing Then
                fn.Select
            Else
                MsgBox "Search Value Not Found!", vbInformation, "NO MATCH"
            End If
    End If
End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,378
Messages
5,528,341
Members
409,817
Latest member
JiNXX9500

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top