1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Private Sub CommandButton1_Click()
Dim c As Range, Plage As Range, LB As ListBox
If Me.TextBox1.Text = "" Or Not IsNumeric(Me.TextBox1.Text) Then Exit Sub
With Sheets("Sheet1")
.[A:F].ClearContents
ligne = 0
Set Plage = .Range(.[H3], .Cells(.Rows.Count, 8).End(xlUp))
Me.ListBox1.Clear
For Each c In Plage
For i = 2 To .Cells(c.Row, .Columns.Count).End(xlToLeft).Column - 4 Step 5
If c.Offset(, i + 2) <= CInt(Me.TextBox1.Text) And c.Offset(, i + 2) > 0 Then
ligne = ligne + 1
.Cells(ligne, 1) = c.Value
.Cells(ligne, 2) = c.Offset(, i).Value
.Cells(ligne, 3) = c.Offset(, i + 1).Value
.Cells(ligne, 4) = c.Offset(, i + 2).Value
.Cells(ligne, 5) = c.Offset(, i + 3).Value
.Cells(ligne, 6) = c.Offset(, i + 4).Value
End If
Next i
Next c
.Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 6).Sort .Range("B1"), xlAscending, _
key2:=.Range("A1"), order2:=xlAscending, Header:=xlNo
Set Plage = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp))
For Each c In Plage
Me.ListBox1.AddItem c.Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = c.Offset(, 1).Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = c.Offset(, 2).Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = c.Offset(, 3).Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = c.Offset(, 4).Value
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = c.Offset(, 5).Value
Next c
.[A:F].ClearContents
End With
End Sub
Private Sub UserForm_Activate()
Me.ListBox1.Clear
Me.TextBox1.Text = ""
End Sub |