How to clear a search box

Krown

New Member
Joined
Dec 18, 2023
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
I have the code below for a search box on my worksheet that filters as a type. Is there something simple that I could add so that the search box contents are deleted automatically after I hit enter to search? I don't want to have to manually clear the contents each time.

Thanks.


Private Sub TextBox1_Change()

Application.ScreenUpdating = False

ActiveSheet.ListObjects("Antibodies").Range.AutoFilter Field:=1, Criteria1:="*" & [B2] & "*", Operator:=xlFilterValues

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try Sheets("Sheet name here").Textboxes("Textbox Name Here") = ""
but where to put it? Possibly Lost Focus event (if hitting enter shifts the focus off of the textbox) or tb double click event if not.
 
Upvote 0
Is there something simple that I could add so that the search box contents are deleted automatically after I hit enter

For activex textbox on sheet, try:
VBA Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    'if user press Enter while cursor is in the tetxbox
    If KeyCode = 13 Then TextBox1 = Empty
End Sub
 
Upvote 0
I found this to work:

Sub ClearAntibody()
'
' ClearAntibody Macro

ActiveSheet.OLEObjects("TextBox1").Object.Value = ""

End Sub

Thank you both for the input!
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,089
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