Macro Won't Run From Ribbon

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
Hello -

I created a macro that works perfectly from a button inserted onto the same sheet where the code will run.

This is the macro:

Code:
Sub SISearch(control As IRibbonControl)Dim r As Range, rAll As Range
Dim sTerm As String
    
    sTerm = Application.InputBox(Prompt:="Enter the text you wish to search for.", Title:="InputBox Method", Type:=2)
    Set rAll = Application.InputBox(Prompt:="Select a Range", Title:="InputBox Method", Type:=8)
 
    If rAll Is Nothing Then
        MsgBox "No Range Selected"
    Else
        For Each r In rAll
            If InStr(UCase(r), UCase(sTerm)) Then
                r.Offset(0, 1) = "Text located"
            End If
        Next r
    End If
End Sub

When I try and run this same macro from the Ribbon, I get the following error message:

"Cannot run the macro 'SISearch'. The macro may not be available in this workbook or all macros may be disabled.

I can't understand why it won't run. I have confirmed macros are enabled, and if I try and run other commands such as opening a userform from the ribbon, it works fine - it's only this one.

Can anyone advise why it won't work?
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Which module is that code in and how did you add the button to the ribbon?
 
Upvote 0
Dear God,

Why do I take up space on these forums with questions that have simple answers?

Rory,

Thanks so much. Ironically enough, your question game me the answer. I had the code u a worksheet. As soon as I modified with a module, it worked.

THanks so much.

One final question though - since I'm using application.inputbox instead of just inputbox, where and how do I program it so if the user selects "Cancel" it exits the sub? Right now if I try and select cancel it gives an error message.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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