Searching Entire Worksheet with Command Button

LauraM88

New Member
Joined
Oct 2, 2012
Messages
1
hi

I'm new to VBA, but I managed to get this code to work on another sheet, but using it in a new sheet I obviously have to change the range it is searching within (Highlighted in Italics) It needs to be changed to search the entire workbook.

Any help?

Private Sub cmdFind_Click()

On Error GoTo NotFound

Sheets("Matrix").Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Select


strName = InputBox(Prompt:="Enter name of Sub Contractor.", _
Title:="ENTER SUB CONTRACTOR", Default:="Sub Contractor")

If strName = "Sub Contractor" Or strName = vbNullString Then
MsgBox ("No Name Entered")
Exit Sub

End If

Selection.Find(What:=strName, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext, MatchCase:=False).Activate

ActiveCell.Select
Exit Sub

NotFound: MsgBox ("Sub Contractor Not found")

Exit Sub

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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