Advertisement
Guest User

excel vba combobox hide/show sheets (test 2)

a guest
Dec 28th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub DropDown2_Initialize()
  2.     Me.DropDown2.AddItem ("all")
  3.     With DropDown2
  4.         Dim year_counter As Integer
  5.         For year_counter = 2012 To 2025
  6.             .AddItem (year_counter)
  7.         Next year_counter
  8.     End With
  9. End Sub
  10.  
  11.  
  12. Sub DropDown2_Change()
  13.  
  14.     Call hideAllMonthlySheets
  15.  
  16.         If DropDown2.Value = "all" Then
  17.             Call showAllMonthlySheets
  18.         ElseIf DropDown2.Value > 2000 Then
  19.             For month_counter = 1 To 12
  20.                Sheets("subtotals-" + DropDown2.Value + "-" + month_counter).Visible = xlSheetVisible
  21.             Next month_counter
  22.        End If
  23.  
  24.     End With
  25. End Sub
  26.  
  27. Sub showAllMonthlySheets()
  28.     Dim year_counter As Integer
  29.     For year_counter = 2012 To 2025
  30.         Dim month_counter As Integer
  31.         For month_counter = 1 To 12
  32.             Sheets("subtotals-" + year_counter + "-" + month_counter).Visible = xlSheetVisible
  33.         Next month_counter
  34.     Next year_counter
  35. End Sub
  36.  
  37.  
  38. Sub hideAllMonthlySheets()
  39.     For year_counter = 2012 To 2025
  40.         For month_counter = 1 To 12
  41.             Sheets("subtotals-" + DropDown2.Value + "-" + month_counter).Visible = xlSheetHidden
  42.         Next month_counter
  43.     Next year_counter
  44.  
  45. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement