Advertisement
YasserKhalil2019

T4521_Create Worksheet If Not Exists By ListBox On UserForm

Jan 12th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. https://excel-egy.com/forum/t4521
  2. ---------------------------------
  3.  
  4. Private Sub UserForm_Initialize()
  5. With Me.ListBox1
  6. .AddItem "salem"
  7. .AddItem "ahmad"
  8. .AddItem "nyef"
  9. .AddItem "rami"
  10. End With
  11. End Sub
  12.  
  13. Private Sub CommandButton1_Click()
  14. Dim ws As Worksheet, b As Boolean, s As String, x As Integer
  15.  
  16. For x = 0 To ListBox1.ListCount - 1
  17. If ListBox1.Selected(x) = True Then
  18. s = ListBox1.List(x): b = False
  19. For Each ws In Worksheets
  20. If ws.Name = s Then b = True: Exit For
  21. Next ws
  22.  
  23. If b = True Then
  24. Application.Goto Sheets(s).Range("A1"): [A1] = Date
  25. Else
  26. Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = s: [A1] = Date
  27. Columns(1).AutoFit
  28. End If
  29. End If
  30. Next x
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement