'Auteur job75
Sub AutoSize_Columns()
Set ListB = UserForm1.ListBox1
Set Fm = UserForm1.Frame1
On Error Resume Next
With Sheets("Base")
tb = .Range("a2:k" & .Range("k" & Rows.Count).End(xlUp).Row).Value
Bd = .Range("a1:k1")
For i = 1 To .UsedRange.Columns.Count
NbrDeCol = i
Next i
Premlig = 2
DernLig = .Range("a1:k1").End(xlDown).Row
ReDim Tablo(Premlig To DernLig, 1 To NbrDeCol), LenCar(1 To NbrDeCol)
For C = 1 To NbrDeCol: LenCar(C) = 0
For L = Premlig To DernLig
Z$ = .Cells(L, C): If IsNumeric(Z$) Then Z$ = Z$ & " "
Tablo(L, C) = .Cells(L, C): If Len(Z$) > LenCar(C) Then LenCar(C) = Len(Z$)
If C = 4 Or C = 7 Then LenCar(C) = 0 'masque les colonnes choisies
Next: Next
End With
FontName$ = "Arial": FontSize$ = 8: Taille$ = 6
ColWidth$ = LenCar(1) * Taille: ListWith$ = LenCar(1) * Taille$
For C = 2 To NbrDeCol
ColWidth$ = ColWidth$ & ";" & (LenCar(C) * Taille$)
ListWith$ = ListWith$ + (LenCar(C) * Taille$)
Next
ListWith$ = ListWith$ + 10 'pour l'ascenseur
With ListB
.Width = ListWith$ - 140 'en premier
.ColumnCount = NbrDeCol
.ColumnWidths = ColWidth$
.Font.Size = FontSize
.Font.Name = FontName$
.List = tb
End With
'adapte l'userform
UserForm1.Width = ListB.Width + 40 'idem mais pour le cadre de l'userform
Fm.ScrollWidth = ListB.Width + 150
'UserForm1.ListBox2 = ListB.Width 'idem mais pour le cadre de l'userform
Fm.Width = ListB.Width + 3
Fm.ScrollBars = 1
End Sub