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 41 42 43 44 45 46 47 48
| Private Sub CommandButton2_Click()
If Me.TextBox1.Value = "" Then
MsgBox "Veuillez indiquer un nom de feuille, merci."
Me.TextBox1.SetFocus
Exit Sub
End If
If Me.TextBox2.Value = "" Then
MsgBox "Veuillez indiquer un numéro d'identification, merci."
Me.TextBox2.SetFocus
Exit Sub
End If
'création d'une feuille pour y copier les données
Dim sh As Worksheet
Set sh = Worksheets.Add
sh.Name = TextBox1
' Rechercher dans la liste, historique du matériel voulu
Dim LastLign As Long ' Dernière ligne de la liste dans la feuille SituationMateriel
Dim NewLign As Long 'Dernière ligne de la liste dans la feuille recherche Matériel
Dim Pcellule As Range 'Première cellule trouver
Dim Num As String 'Code d'identification
LastLign = Range("SituationMateriel!B1048576").End(xlUp).Row
NewLign = 2
Num = TextBox2
With Worksheets("SituationMateriel").Range("B1:B" & LastLign)
Set c = .Find(Num)
Set Pcellule = c 'enregistre le premier élémént trouver
If Not c Is Nothing Then
Do
c.EntireRow.Copy Destination:=Worksheets(TextBox1).Range("B" & NewLign) 'copie la ligne dans l'autre feuille
Set c = .FindNext(c) ' recherche si il y a un autre code dans la liste
NewLign = NewLign + 1
Loop While Not c Is Nothing And c <> Pcellule
End If
End With
'Vide la BDD
Unload Me
RechercherMateriel.Hide
Choix_Action.Show
End Sub |
Partager