Hi all,
I'm using the following code to hide/show charts and scrollbars.
Is there a way to reduce to code in size? Especially this part:
You can imagine if I have 50 charts the length of the code will be very big.
I'm using the following code to hide/show charts and scrollbars.
Code:
Private Sub cmbDepartment_Change()Dim SelectedChart As String
Dim SelectedScrollbar As String
Dim blnVisible As Boolean
Me.cmbFilter.ListFillRange = Me.cmbDepartment
Range("B16") = cmbDepartment.ListIndex + 1
SelectedChart = "Chart" & Range("B16")
SelectedScrollbar = "Scrollbar" & Range("B16")
ActiveSheet.ChartObjects("Chart1").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar1").Visible = blnVisible
ActiveSheet.ChartObjects("Chart2").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar2").Visible = blnVisible
ActiveSheet.ChartObjects("Chart3").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar3").Visible = blnVisible
ActiveSheet.ChartObjects("Chart4").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar4").Visible = blnVisible
If Not blnVisible Then ActiveSheet.ChartObjects(SelectedChart).Visible = True
If Not blnVisible Then ActiveSheet.Shapes(SelectedScrollbar).Visible = True
End Sub
Is there a way to reduce to code in size? Especially this part:
Code:
ActiveSheet.ChartObjects("Chart1").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar1").Visible = blnVisible
ActiveSheet.ChartObjects("Chart2").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar2").Visible = blnVisible
ActiveSheet.ChartObjects("Chart3").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar3").Visible = blnVisible
ActiveSheet.ChartObjects("Chart4").Visible = blnVisible
ActiveSheet.Shapes("Scrollbar4").Visible = blnVisible
You can imagine if I have 50 charts the length of the code will be very big.
Last edited: