Advertisement
Guest User

excel vba combobox hide/show sheets (test)

a guest
Dec 28th, 2013
248
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.         For year_counter = 2012 To 2025
  5.             .AddItem (year_counter)
  6.         Next year_counter
  7.     End With
  8. End Sub
  9.  
  10.  
  11. Sub DropDown2_Change()
  12.  
  13.     hideAllMonthlySheets
  14.  
  15.         If DropDown2.Value = "all" Then
  16.             showAllMonthlySheets
  17.         ElseIf DropDown2.Value > 2000 Then
  18.             For month_counter = 1 To 12
  19.                Sheets("subtotals-" + DropDown2.Value + "-" + month_counter).Visible = xlSheetVisible
  20.             Next month_counter
  21.        End If
  22.  
  23.     End With
  24. End Sub
  25.  
  26. Sub showAllMonthlySheets()
  27.     For year_counter = 2012 To 2025
  28.         For month_counter = 1 To 12
  29.             Sheets("subtotals-" + DropDown2.Value + "-" + month_counter).Visible = xlSheetVisible
  30.         Next month_counter
  31.     Next year_counter
  32. End Sub
  33.  
  34.  
  35. Sub hideAllMonthlySheets()
  36.     For year_counter = 2012 To 2025
  37.         For month_counter = 1 To 12
  38.             Sheets("subtotals-" + DropDown2.Value + "-" + month_counter).Visible = xlSheetHidden
  39.         Next month_counter
  40.     Next year_counter
  41.  
  42. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement