XL 2016 Fermeture d'un Userform

Myst

XLDnaute Occasionnel
Bonjour a tous
j'essaye de fermer l'Userform1 a la fin du code ci-dessous
merci

VB:
Private Sub CommandButton_Click()
    On Error GoTo ErrSheet
  Dim n&: n = Cells(Rows.Count, 1).End(3).Row: If n = 1 Then Exit Sub
  Dim sh As Worksheet, T, v$, k As Byte, p%, i&
  n = n - 1: T = [A2].Resize(n): ActiveCell.Select
  p = Worksheets.Count: Application.ScreenUpdating = 0
  For i = 1 To n
    v = T(i, 1)
    If v <> "" Then
      k = 0: Set sh = Worksheets(v)
      If k = 1 Then
        Worksheets("EXEMPLE").Copy , Worksheets(p)
        ActiveSheet.Name = v: p = p + 1
      End If
    End If
  Next i
  Worksheets("NOMS").Select
'Copier le nom de chaque feuille dans chaque cellule A3
Dim ws As Worksheet
For Each ws In Worksheets
    ws.Range("A3").Value = ws.Name
Next ws

  Exit Sub
'si la feuille existe déjà :
ErrSheet: k = 1: Resume Next

Unload UserForm1

End Sub
 

Discussions similaires