Search box with key to find next value

pablik01

New Member
Joined
Mar 19, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, I was looking for various solutions on the Internet, but I didn't find anything that could help me. So here's the code:

Private Sub TextBox1_Change()
Dim foundRng As Range


Set haslo = TextBox1
Set foundRng = Range("D3:D19").Find(haslo)

If foundRng Is Nothing Then
Exit Sub

Else
Application.Goto Reference:=foundRng
End If
End Sub

it's a mini search engine, or that's how it's supposed to work. In the current form, the entered value is searched for, but the problem appears, when there are more such values because the search stops at the first value found - is it possible to code this field so that after pressing the enter key, it goes to the next cell with the entered text? I have been working with VBA for 3 weeks and it is beyond my abilities
 

Attachments

  • 1616141486922.jpeg
    1616141486922.jpeg
    3 KB · Views: 12
  • 1616141486893.png
    1616141486893.png
    312 bytes · Views: 12
  • 1616141486937.jpeg
    1616141486937.jpeg
    2.3 KB · Views: 13
  • 1616141486908.jpeg
    1616141486908.jpeg
    2.8 KB · Views: 11

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
So we want to search the range"D3:D19"
And what do you want to do when the value is found.
For your script looks like it wants to goto the range.
But if found more then once do what.
 
Upvote 0
I do not see how a Textbox change event can be used.
If I want to search for "Alpha" the second I enter "A" into the textbox the script runs.

Here is a script use with a Command Button and a Textbox.

VBA Code:
Private Sub CommandButton1_Click()
'Modified  3/19/2021  4:40:33 AM  EDT
Dim r As Range
Dim x As Long
x = 0
For Each r In Range("D3:D19")
    If r.Value = TextBox1.Value Then
        r.Offset(, 1).Value = "Found Here"
        x = x + 1
    End If
Next

If x = 0 Then MsgBox TextBox1.Value & vbNewLine & "Not found"

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,125
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