Link to home
Start Free TrialLog in
Avatar of barnescs
barnescsFlag for United States of America

asked on

Button to run Macro

I have the following macro and need to create a button on an Excel worksheet to run it.  How do i create the button and then attach the macro to it?

Sub FindName()
    Dim rngName As Range
    Dim wks As Worksheet
    Dim tb As TextBox
    ' this is the input cell - adjust as need
    Set rngName = Sheets("Summary").Range("A15")
    For Each wks In ActiveWorkbook.Worksheets
        For Each tb In wks.TextBoxes
            If InStr(1, tb.Text, rngName.Value, vbTextCompare) > 0 Then
                wks.Activate
                Exit Sub
            End If
        Next tb
    Next wks
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or right-click on the toolbars and select customise - Then select macro from the list. Add the button
Avatar of barnescs

ASKER

rorya - this works great!!!  Thanks so very much for all your help!  :-)