• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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
                Exit Sub
            End If
        Next tb
    Next wks
End Sub
1 Solution
Rory ArchibaldCommented:
In 2003 or prior:
View-Toolbars-Forms, click the Button control and draw one on the sheet - this will pop up a dialog to assign a macro to the button.
In 2007 or later:
Developer Tab, Insert-Forms control button and the rest is as for 2003 or earlier.

Or right-click on the toolbars and select customise - Then select macro from the list. Add the button
barnescsAuthor Commented:
rorya - this works great!!!  Thanks so very much for all your help!  :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now