Search Function

pzamory

Board Regular
Joined
May 2, 2002
Messages
135
Good morning.

I am able to copy/paste this search function (see below) into a module. I assign a Search "button" to access this module and it seems to work just fine. My aim is to be able to search for text throughout multiple workbooks in an Excel sheet.

The problem is that when I exit out of the Excel sheet (Book1) and open it up again, I get an error message and the search function no longer works. Looking for any direction and/or guidance. Thanks very much.

Error message: Cannot run the macro 'Book1.xlsm!Findmesheet! - The macro may not be available in this workbook or all macros may be disabled

Code:
Option Explicit

Sub FindMeSheet()

Dim CheckNum$
Dim varSheets As Variant
Dim i As Long
Dim c As Range

    CheckNum = InputBox("Enter your word/number.", "Sheet (??) Chaser")
    If CheckNum = vbNullString Then Exit Sub

varSheets = Array("Sheet2", "Sheet3", "Sheet4")

For i = LBound(varSheets) To UBound(varSheets)
   With Sheets(varSheets(i))
   
      Set c = .UsedRange.Find(What:=CheckNum, LookIn:=xlValues)
      
      If Not c Is Nothing Then
         MsgBox c.Address & " On " & Sheets(varSheets(i)).Name
      End If
      
   End With
Next
End Sub
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
A few questions:

Is the workbook called Book1.xlsm?
Did you enable macros?
Which module is the code in?
 
Upvote 0
Module Name: Findmesheet
Workbook is called Book1.xlsm
I saved the file as "macro enabled". Is there another step that I am missing for enabling macros?

Thanks Rory
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,185
Members
448,872
Latest member
lcaw

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