Dimension listbox

rlebigre

XLDnaute Nouveau
Bonjour à tous

Je rencontre un problème lors d'un dimensionnement de listbox en fonction du nombre de valeur contenue dedans.

Lorsque je fais en pas à pas tout marche normalement. Mais lorsque je fait en cotinu ca ne marche plus.

ma hauteur de listbox est une varaible incrémentée à chaque fois qu'une condtion if est vrai

Voici ma ligne de commande:
chx_appareil.ListBox1.Height = k
'k' est incrémenter par pas de 15.5 à chaque condtion if vrai

J'ai essayé de déplacer la ligne de commande mais ca ne marche pas. Merci de m'aider si vous pouvez.

@+
 

rlebigre

XLDnaute Nouveau
Tontoncarton, le forum,

Excusez-moi si je n'ai pas été sufisamment clair. Voici le code de ma macro:

Private Sub userform_initialize()
Dim ws As Worksheet
Dim i As Byte, j As Byte
Dim temp As String
Dim k As integer
Dim hauteur_listbox As Variant
'
chx_appareil.Caption = ThisWorkbook.Name
k = 0
For Each ws In Worksheets
If Left(ws.Name, 4) <> 'Accu' _
And Left(ws.Name, 3) <> 'His' _
And Left(ws.Name, 3) <> 'Tra' _
And Left(ws.Name, 3) <> 'Neg' _
And Left(ws.Name, 3) <> 'Jaq' _
And Left(ws.Name, 3) <> 'Alb' _
And Left(ws.Name, 3) <> 'Lis' _
And Left(ws.Name, 3) <> 'Mat' _
And Left(ws.Name, 3) <> 'NB ' _
And Left(ws.Name, 3) <> 'Ret' _
And Left(ws.Name, 3) <> 'Boi' _
And Left(ws.Name, 3) <> 'tab' _
And Left(ws.Name, 3) <> 'APA' _
And Left(ws.Name, 3) <> 'APN' _
Then ListBox1.AddItem ws.Name: k = k + 1
Next ws
For i = 0 To ListBox1.ListCount
For j = i + 1 To ListBox1.ListCount - 1
If ListBox1.List(i) > ListBox1.List(j) Then
temp = ListBox1.List(i)
ListBox1.List(i) = ListBox1.List(j)
ListBox1.List(j) = temp
End If
Next j
Next i
' Hauteur de la listbox
hauteur_listbox = k * 15.5
chx_appareil.CommandButton1.Top = 114 + hauteur_listbox
chx_appareil.CommandButton3.Top = 114 + hauteur_listbox
chx_appareil.Height = 168 + hauteur_listbox
'
End Sub

Voila
@+