How to have Excel clear the Find and Replace box after a cell has been selected by the "Find Next" button

TheJay

Active Member
Joined
Nov 12, 2014
Messages
364
Office Version
  1. 2019
Platform
  1. Windows
Hello there, I need to search for numbers and after it has been highlighted on my spreadsheet, I would like VBA that clears the "Find what" box, so I can enter the next search query without messing about.

Could someone please tell me how this is achieved?

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this - I think it shall do the job for you

VBA Code:
Sub ClearSearch

Cells.Find(What:="", After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False).Activate

End Sub
 
Upvote 0
Thanks Sanjay, what will force the code to run though? I added it to the sheet and tried a search and it didn't do anything.
 
Upvote 0
Try to search any thing or Find Replace anything - then run this code and see if it clears the Find What or not

It is designed to work in background without popping any message

try it and update
 
Upvote 0
Okay, I inserted it into the sheet and then ran it manually. It just moved the focus to the next column and didn't clear the search query entered previously.
 
Upvote 0
I think I forgot to mention one thing -
  • If you insert this VBA on a particular sheet, it shall work on that sheet
  • But if you insert it on General (for all sheets) it shall work universally
  • See Screenshot
  • I tried with my workbook it worked fine - as it is supposed to search after active cell (you can see this word in code)
 

Attachments

  • Screenshot 2022-09-15 at 16.04.13.png
    Screenshot 2022-09-15 at 16.04.13.png
    20.4 KB · Views: 2
Upvote 0
Thanks for your reply.

I'm not sure I understand. I don't know if I explained very well.

When I press Ctrl & F, I want the find box to appear but empty, so I can type something to search for without having to delete what I last searched for. I'm looking for a solution that is automatic, not involving pressing a button or going into the VBA and manually running the code.
 
Upvote 0
I've found a work around, but I cannot figure out how to get BACKSPACE to operate as part of a SendKeys combination.

Created a module
VBA Code:
Sub ResetFind()
Application.CommandBars.FindControl(ID:=1849).Execute
Application.SendKeys.Send ("^a{BS}")
End Sub

Then bound Ctrl & F to that macro.

The search box comes up and if there is any text in it, it highlights it all and then it can be overtyped. I'd still like to know how to send BACKSPACE or DELETE after ctrl and a. What's wrong with my code please?
 
Upvote 0
I don't know if there is another way without using SendKeys, but adding VBA to a new module, one of the sheets or ThisWorkbook and then binding it to Ctrl + F works.

VBA Code:
Sub ResetFind()
Application.CommandBars.FindControl(ID:=1849).Execute
Application.SendKeys "^a{BACKSPACE}"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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