+ Reply to Thread
Results 1 to 2 of 2

Excel Toggle Button Code

Hybrid View

Allyb2928 Excel Toggle Button Code 07-18-2022, 11:17 AM
6StringJazzer Re: Excel Toggle Button Code 07-18-2022, 12:13 PM
  1. #1
    Registered User
    Join Date
    07-15-2022
    Location
    Buffalo, NY
    MS-Off Ver
    16
    Posts
    1

    Excel Toggle Button Code

    I have created a toggle button to hide multiple non-adjacent columns. It works, but when I filter a column, the button stops working. The only way to get it to work again is if I re-sort the column I had filtered with, back to A-Z.

    Is there a way to fix this? Is there some code I can add for it to reset after a filter is used?

    The code I have set:
    Private Sub ToggleButton1_Click()
    
        Dim xAddress As String
        Dim splitAddress As Variant
        xAddress = "Q,S,U,W,Y,AA,AG,AI,AK,AU" 'change this to the column letters
        splitAddress = Split(xAddress, ",")
    
        If ToggleButton1.Value Then
            For Each Var In splitAddress
                Application.ActiveSheet.Columns(Var).Hidden = True
                ToggleButton1.Caption = "Show Column"
            Next Var
    
        Else
            For Each Var In splitAddress
                Application.ActiveSheet.Columns(Var).Hidden = False
                ToggleButton1.Caption = "Hide Column"
            Next Var
        
        End If
            
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 07-18-2022 at 12:11 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Excel Toggle Button Code

    What does "the button stops working" mean? What happens when you click the button? Nothing? Have you set a checkpoint in your code to see if the code is invoked? Maybe the Sub is called but just doesn't do what you expect.

    If your file does not have sensitive data, please attach it so we can try to run your code. See yellow banner at the top of the page.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. [SOLVED] Simpler way for Custom Ribbon toggle button code ?
    By karmapala in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2020, 01:27 AM
  2. [SOLVED] Assign Code to Shapes Instead of Toggle Button
    By crazyforexcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2020, 12:01 PM
  3. How Do I Create a Toggle Button and add Code to it?
    By vba_madness in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-25-2016, 04:59 AM
  4. [SOLVED] Toggle Button Code
    By gavinduffy01 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2013, 05:21 AM
  5. [SOLVED] UserForm Toggle Button Code
    By JasonRay in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2013, 05:29 PM
  6. Code for button to toggle row height
    By Bentleywp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-03-2011, 10:39 AM
  7. toggle button & event code
    By benb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2005, 04:06 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