Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Private Sub REFRESH_COMBOBOX1()
  2. Dim ws As Worksheet
  3. ComboBox1.Clear
  4. For Each ws In ThisWorkbook.Sheets
  5. If ws.Visible Then ComboBox1.AddItem(ws.Name)
  6. Next ws
  7. End Sub
  8.  
  9.  
  10. Private Sub ComboBox1_DropButtonClick()
  11. REFRESH_COMBOBOX1
  12. End Sub
  13.  
  14. Sub REFRESH_COMBOBOX1()
  15. Dim ws As Worksheet
  16. Dim i As Long
  17. Do While ComboBox1.ListCount > 0
  18. ComboBox1.RemoveItem (0)
  19. Loop
  20. For Each ws In ThisWorkbook.Sheets
  21. If ws.Visible Then ComboBox1.AddItem (ws.Name)
  22. Next ws
  23. End Sub
  24.  
  25. Call RefreshSheetList()
  26.  
  27. Private Sub RefreshSheetList()
  28. With ComboBox1
  29. .Clear
  30. For n=1 To ActiveWorkbook.Sheets.Count
  31. .AddItem ActiveWorkbook.Sheets(n).Name
  32. Next n
  33. End With
  34. End Sub
  35.  
  36. Sub CommandButton1_Click()
  37. Dim w as Worksheet
  38. With ActiveWorkbook
  39. Set w = .Worksheets.Add(After:=.Worksheets(.Worksheets.Count))
  40. w.Name = Me.TextBox1.Text
  41. End With
  42. Call RefreshSheetList()
  43. End Sub
  44.  
  45. Private Sub REFRESH_COMBOBOX1() ' Routine for refreshing the list of names in box
  46.  
  47. Dim ws As Worksheet ' need a worksheet variable
  48. ComboBox1.Clear ' clear the current list
  49.  
  50. ' Cycle through every worksheet in the book, if it is NOT hidden then add name to list
  51. For Each ws In ThisWorkbook.Sheets
  52. If ws.Visible Then ComboBox1.AddItem (ws.Name)
  53. Next ws
  54. End Sub '
  55.  
  56.  
  57. ' Separate routine to register the user putting focus on the box
  58. ' This happens every time the user clicks on or enters ComboBox1
  59. Private Sub ComboBox1_Enter()
  60. REFRESH_COMBOBOX1 ' Calling the routine above
  61. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement