Share via

How to edit this vba code?

Mariner 160 Reputation points
2026-04-01T08:31:03.1833333+00:00

The code below causes an Info_Button and its corresponding Info_Box to appear or disappear from a dashboard depending on the active state of another button. The Info button references in this code are:

Info_Button_Deliveries

Info_Box_Deliveries

 

I want to add two more sets of Info Buttons:

Info_Button_Projects

Info_Box_Projects

 

Info_Button_Salaries

Info_Box_Salaries

 

How do I do that?

Sub 
 
    With ActiveSheet
       
        If .Shapes("Toggle_Circle_Info").Fill.ForeColor.RGB = RGB(255, 255, 255) Then
 
            'Visibility Info Elements
            With .Shapes("Info_Button_Deliveries")
                .Visible = True
                .Fill.ForeColor.RGB = RGB(255, 255, 255)
            End With
 
            .Shapes("Info_Box_Deliveries").Visible = False
 
            'Toggle Button Status
            Call Change_Toggle_Button_Status(.Shapes("Toggle_Circle_Info"),
                                             .Shapes("Toggle_Background_Info"),
                                             .Shapes("Toggle_Textbox_Info"),
                                             True)
 
        Else
           
            'Visibility Info Elements
            .Shapes("Info_Button_Deliveries").Visible = False
            .Shapes("Info_Box_Deliveries").Visible = False
 
            'Toggle Button Status
            Call Change_Toggle_Button_Status(.Shapes("Toggle_Circle_Info"),
                                             .Shapes("Toggle_Background_Info"),                                              
                                             .Shapes("Toggle_Textbox_Info"),
                                             False)
       
        End If
 
    End With
 
End Sub
Microsoft 365 and Office | Excel | For home | Windows
0 comments No comments

Answer accepted by question author

AI answer

2026-04-01T08:31:15.72+00:00

Add the extra shapes anywhere the existing pair is handled. In this procedure there are only two places: inside the If (when the toggle is “on”) and inside the Else (when the toggle is “off”).

For example, extend the code like this:

Sub Toggle_Info()

    With ActiveSheet

        If .Shapes("Toggle_Circle_Info").Fill.ForeColor.RGB = RGB(255, 255, 255) Then

            'Visibility Info Elements - ON
            With .Shapes("Info_Button_Deliveries")
                .Visible = True
                .Fill.ForeColor.RGB = RGB(255, 255, 255)
            End With
            .Shapes("Info_Box_Deliveries").Visible = False

            With .Shapes("Info_Button_Projects")
                .Visible = True
                .Fill.ForeColor.RGB = RGB(255, 255, 255)
            End With
            .Shapes("Info_Box_Projects").Visible = False

            With .Shapes("Info_Button_Salaries")
                .Visible = True
                .Fill.ForeColor.RGB = RGB(255, 255, 255)
            End With
            .Shapes("Info_Box_Salaries").Visible = False

            'Toggle Button Status
            Call Change_Toggle_Button_Status( _
                    .Shapes("Toggle_Circle_Info"), _
                    .Shapes("Toggle_Background_Info"), _
                    .Shapes("Toggle_Textbox_Info"), _
                    True)

        Else

            'Visibility Info Elements - OFF
            .Shapes("Info_Button_Deliveries").Visible = False
            .Shapes("Info_Box_Deliveries").Visible = False

            .Shapes("Info_Button_Projects").Visible = False
            .Shapes("Info_Box_Projects").Visible = False

            .Shapes("Info_Button_Salaries").Visible = False
            .Shapes("Info_Box_Salaries").Visible = False

            'Toggle Button Status
            Call Change_Toggle_Button_Status( _
                    .Shapes("Toggle_Circle_Info"), _
                    .Shapes("Toggle_Background_Info"), _
                    .Shapes("Toggle_Textbox_Info"), _
                    False)

        End If

    End With

End Sub

Ensure that the shapes on the sheet are actually named Info_Button_Projects, Info_Box_Projects, Info_Button_Salaries, and Info_Box_Salaries (use the Name Box when the shape is selected). The macro can then be assigned to a button or ActiveX control as usual.


References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.