Excel 2016 VBA - Show/Hide multiple shape groups I have the following code I'm using to show/hide multiple shape groups in Excel 2016 using VBA and macros:

   Sub Pic_1_SA_click()
   ActiveSheet.Shapes("Group 23").Visible = True
   ActiveSheet.Shapes("Group 71").Visible = False
   ActiveSheet.Shapes("Group 19").Visible = False
   ActiveSheet.Shapes("Group 20").Visible = False
   End Sub

   Sub Pic_1_SB_click()
   ActiveSheet.Shapes("Group 23").Visible = False
   ActiveSheet.Shapes("Group 71").Visible = True
   ActiveSheet.Shapes("Group 19").Visible = False
   ActiveSheet.Shapes("Group 20").Visible = False
   End Sub

   Sub Pic_2_SA_click()
   ActiveSheet.Shapes("Group 23").Visible = False
   ActiveSheet.Shapes("Group 71").Visible = False
   ActiveSheet.Shapes("Group 19").Visible = True
   ActiveSheet.Shapes("Group 20").Visible = False
   End Sub

   Sub Pic_2_SB_click()
   ActiveSheet.Shapes("Group 23").Visible = False
   ActiveSheet.Shapes("Group 71").Visible = False
   ActiveSheet.Shapes("Group 19").Visible = False
   ActiveSheet.Shapes("Group 20").Visible = True
   End Sub


Now the above is somewhat tedious if I plan to add more buttons. Is there any way to do this more efficiently?
The simple answer is to use pass an array of names to the Shapes.Range, hide all 4 Groups, and then make the one Group visible.  


ActiveSheet.Shapes.Range(Array("Group 19", "Group 20", "Group 23", "Group 71")).Visible = msoTrue
ActiveSheet.Shapes("Group 20").Visible = msoFalse



Reference: MSDN - Shapes.Range Property(Excel)

Considering that all Group default names start with "Group ", you could further simplify it by creating a function that will return the ShapeRange based of the Group number.



Public Function getGroupRange(ws As Worksheet, ParamArray GroupNames() As Variant) As ShapeRange
    Dim n As Long
    For n = 0 To UBound(GroupNames)
        If IsNumeric(GroupNames(n)) Then GroupNames(n) = "Group " &amp; GroupNames(n)
    Next
    Set getGroupRange = ws.Shapes.Range(GroupNames)

End Function




Sub Pic_1_SA_click()
    getGroupRange(ActiveSheet, 19, 20, 23, 71).Visible = msoFalse
    getGroupRange(ActiveSheet, 23).Visible = msoTrue
End Sub

Sub Pic_1_SB_click()
    getGroupRange(ActiveSheet, 19, 20, 23, 71).Visible = msoFalse
    getGroupRange(ActiveSheet, 71).Visible = msoTrue
End Sub

Sub Pic_2_SA_click()
    getGroupRange(ActiveSheet, 19, 20, 23, 71).Visible = msoFalse
    getGroupRange(ActiveSheet, 19).Visible = msoTrue
End Sub

Sub Pic_2_SB_click()
    getGroupRange(ActiveSheet, 19, 20, 23, 71).Visible = msoFalse
    getGroupRange(ActiveSheet, 20).Visible = msoTrue
End Sub