Private Sub CommandButton1_Click()
Dim WsCible As Worksheet
Dim nb As Integer
Dim i As Byte
Dim j As Integer
Dim k As Byte
With Application
.ScreenUpdating = False 'on inibe
.DisplayAlerts = False 'idem
End With
With ActiveWorkbook 'avec le classeur actif
If FeuilleExiste("IMPRIM") = True Then .Sheets("IMPRIM").Delete 'Test , si la feuille IMPRIM existe , on la supprime
Application.DisplayAlerts = True 'on réactive l'alerte
Set WsCible = .Sheets.Add(, Worksheets(Worksheets.Count))
With WsCible
.Name = "IMPRIM"
nb = UserForm2.ListView1.ListItems.Count
For i = 1 To UserForm2.ListView1.ColumnHeaders.Count
With .Cells(4, i)
.Value = UserForm2.ListView1.ColumnHeaders(i)
With .Font
.Bold = True
.Name = "Arial"
.Size = 12
End With
End With
Next i
For j = 1 To UserForm2.ListView1.ListItems.Count
.Cells(j + 4, 1) = UserForm2.ListView1.ListItems(j).Text 'on colle la valeur
For k = 1 To UserForm2.ListView1.ColumnHeaders.Count - 1 'pour chaque colonne de la listView
With .Cells(j + 4, k + 1) 'avec la cellule ainsi determinée
Select Case k ' selon la valeur de K
Case 4, 5 'si =4 ou 5 on colle et on formate
.Value = Format(UserForm2.ListView1.ListItems(j).ListSubItems(k).Text, "00000")
.NumberFormat = "m/d/yyyy"
Case Else 'autre cas
.Value = UserForm2.ListView1.ListItems(j).ListSubItems(k).Text 'on colle la valeur
End Select
.EntireColumn.AutoFit 'on formate la colonne
End With
Next k 'autre colonne
Next j 'autre ligne
With .Range(.Cells(4, 1), .Cells(4 + nb, k)) 'avec cette plage de donnees ainsi déterminée
With .Borders 'on formate les bordures
.LineStyle = xlContinuous
.Weight = xlThin
End With
End With
Stop
End With
End With
Application.ScreenUpdating = True 'on réactive le defilement
'If Application.Dialogs(xlDialogPrinterSetup).Show = True Then Stop: UserForm2.PrintForm
'Stop
End Sub