Use VBA "FIND" without effecting the previous (and future) manual searches.

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
I can't figure out why this has changed.

I run a manual Ctrl+F find to find a 5 digit number,

Run macro that uses a find function

Code:
Set Loc = Sheets("comments").Range("a1:a10000").Find(search_string, , , xlWhole)

Once the macro is complete I want to Ctrl+F to search again for the same 5 digit number.

However now the find box is prefilled with the value from search_string.


Is it possible to carry out the find without effecting the manual find box?
or reset the find box back to its previous state?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
is there an alternative way of finding "search_string" without using the find function?
 
Upvote 0
Try
Code:
Sub MyFind()
   Dim Loc As Range
   Dim res As Variant
   Dim search_string As String
   
   search_string = "Devon"
   With Sheets("comments")
      res = Application.Match(search_string, .Range("A1:A10000"), 0)
      If Not IsError(res) Then Set Loc = Range("A" & res)
   End With
End Sub
 
Upvote 0
Nice one, thank you very much.


I enjoyed my little test as well :)

Code:
[COLOR=#333333]Sub MyFind()[/COLOR]   Dim Loc As Range
   Dim res As Variant
   Dim search_string As String
   
   search_string = "Devon"
   With Sheets("comments")
      res = Application.Match(search_string, .Range("A1:A10000"), 0)
      If Not IsError(res) Then Set Loc = [COLOR=#ff0000].[/COLOR]Range("A" & res)
   End With [COLOR=#333333]End Sub[/COLOR]
 
Upvote 0
You're welcome & well done for spotting the error
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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