VBA: Trying to create a macro for "FIND"

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
I was trying to create a Macro to have a box popup to find something on the worksheet. I have the code below but I think it needs adjusted.

Code:
Sub find()
'
' find Macro
'
What = InputBox("word to search")
Sheets().Select
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
   
End Sub
It would be nice if the search was not case sensitive.
Also if not to difficult a way to "Find Next" also.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe these two macros will do what you want...
Code:
Sub FindWord()
  Dim What As String
  Application.FindFormat.Clear
  What = InputBox("word to search")
  Cells.Find(What, LookAt:=xlPart, MatchCase:=False).Select
End Sub

Sub FindNextWord()
  Cells.FindNext(ActiveCell).Select
End Sub
 
Upvote 0
Thanks Rick, Is it it possible to have the macros combined somehow ?

I don't see how... you would either have to ask the "Word to search" question everytime you run the macro or, if you did not want to do that, you would only be able to search for one word (the word you answered to the question).
 
Upvote 0
Ok, How about if I created a userform with a search button and a next button. Could the code be modified to do that ??
 
Upvote 0
Ok, How about if I created a userform with a search button and a next button. Could the code be modified to do that ??
When the code was behind a button, I sort of understood why you might want to do what you asked for, but now you are proposing calling up a UserForm and that leads me to ask... why not simply use the built-in Find dialog box that Excel provides? You can either call it up from the menu or Ribbon depending on which version of Excel you have or, more simply to my mind, just press the Ctrl+H keystroke combination?
 
Upvote 0
Thanks for the reply. On the Sheets I am using the ribbon is hidden. There are several different users that look at the sheet and most of them no nothing of Excel.So I have tried to make it as simple as possible. The sheet has several Command Buttons on it now for Basic Functions.
 
Upvote 0
Thanks for the reply. On the Sheets I am using the ribbon is hidden. There are several different users that look at the sheet and most of them no nothing of Excel.So I have tried to make it as simple as possible. The sheet has several Command Buttons on it now for Basic Functions.

Okay, this macro calls the built-in Find dialog which has Find and FindNext built into a single dialog box meaning you can assing the macro to a single button (like you wanted originally) and still have both functionalities. Give it a try and see if it will work out for you...
Code:
Sub ShowFindDialogBox()
  Application.Dialogs(xlDialogFormulaFind).Show
End Sub
 
Upvote 0
Is there a way to have this dialog show the "Find and Replace" dialog? ...The one with a button to "Find All"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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