In Need of a Custom Search Box

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
194
Office Version
  1. 365
Platform
  1. Windows
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.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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
 
Upvote 0
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!

 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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