Button to run Macro

Posted on 2011-04-26
Last Modified: 2012-05-11
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
Question by:barnescs
    LVL 85

    Accepted Solution

    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.

    LVL 10

    Expert Comment

    Or right-click on the toolbars and select customise - Then select macro from the list. Add the button

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I've recently been in need of an Excel macro that could add a letter before the text on multiple cells in an Excel document. My English is as it is, so I will try explain what it does diffrently. If you have an excel document with 2000 rows an…
    Sometimes we don't want to show zeros in our Excel spreadsheets. This is sometimes most evident in our charts. Look at the chart below, all the zero values are visible. I think that all will agree with the fact that zero values are not looking nice …
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now