Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • 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
                wks.Activate
                Exit Sub
            End If
        Next tb
    Next wks
End Sub
0
barnescs
Asked:
barnescs
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.

HTH
Rory
0
 
cjrmail2kCommented:
Or right-click on the toolbars and select customise - Then select macro from the list. Add the button
0
 
barnescsAuthor Commented:
rorya - this works great!!!  Thanks so very much for all your help!  :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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