FIND a value using VBA

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Hi all,

I want to find a value within the workbook.

Manually I would press CTRL + F, type the text in the FIND WHAT field, then set the WITHIN field to WORKBOOK.

When recoded this thru macro and tried to run it again, I got a debug error. See my code below

Code:
Sub Macro5()
    Sheets("Main").Select
    Cells.Find(What:="PATSYS", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
End Sub

I noticed that the Sheet is set when the macro is recorded and that if this sheet is not the active one when I run this code, I get the debug error.

How do I fix this?

Thanks in advance
 
Manually I would press CTRL + F, type the text in the FIND WHAT field, then set the WITHIN field to WORKBOOK.
Just to clarify in relation to the original question .. unfortunately, the red setting is not accessible through vba.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi Peter,

Thanks for the clarification.

I have been wondering why the recorded code does not work. At least now I know it can not be done thru VBA.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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