+ Reply to Thread
Results 1 to 2 of 2

Several Toggle Buttons with same Macros

  1. #1
    Registered User
    Join Date
    05-17-2017
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1

    Several Toggle Buttons with same Macros

    Hi I have created a code for a Toggle button. However I need 50+ toggle buttons in the file with the same code. How I can assign same Macros to all of them?
    Please, see the code below.

    Private Sub ToggleButton1_Click()
    If ToggleButton1.Value = True Then
    ToggleButton1. Caption = "Include"
    Range ("I5"). Value = 1
    Else
    ToggleButton1. Caption = "Exclude"
    Range ("I5"). Value = 0
    End If

    End Sub

    I also need the I5 cell to change according to row number of Toggle Button.

    Can you, please, help me with this?

  2. #2
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Several Toggle Buttons with same Macros

    I don't think you can do that with ActiveX controls - they each have their own click_event - , but with a Userform control or even a Shape, you can assign a macro. You could write code to loop through the appropriate collection, assign the macro using the OnAction property, and rename the objects using some numbering system like "MyToggle01". Then the assigned macro could use the Application.Caller method to get the name of the calling object, use the RIGHT function to grab the last two characters, and change I5.
    Last edited by leelnich; 05-17-2017 at 12:55 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macros with buttons, spin buttons, scroll buttons, etc.
    By qqbbppdd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2013, 09:34 AM
  2. Two Toggle Buttons Working Together
    By sideburns in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2013, 01:47 PM
  3. Filtering Using Toggle Buttons
    By Farmall in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2012, 04:32 PM
  4. Rename Toggle Buttons
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2010, 02:32 PM
  5. [SOLVED] Toggle command buttons
    By GEB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-23-2005, 04:05 PM
  6. Toggle Buttons
    By Momo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2005, 10:06 AM
  7. How do I use Toggle Buttons?
    By fuzzyfreak in forum Excel General
    Replies: 0
    Last Post: 01-21-2005, 01:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1