Private Sub CommandButton2_Click()
Dim ws As Worksheet, WO As Worksheet, DerLig As Long, DerFiltre As Long
Dim c As Range, d As Range, Plage As Range
If TextBox5 = "" Then Exit Sub
Set WO = Worksheets("Formulaire de prêt")
For Each ws In Worksheets
If ws.Name Like Str_Type & "*" Then
With ws
Set c = .Columns(1).Find(TextBox5)
If Not c Is Nothing Then Exit For
End With
End If
Next ws
If c Is Nothing Then
MsgBox "Référence non trouvée": Exit Sub
Else
'MsgBox "référence ok"
'** verifie que le materiel est disponible
DerLig = WO.Range("G" & Rows.Count).End(xlUp).Row - 1
Set d = WO.Columns(7).Find(TextBox5)
If Not d Is Nothing Then
Set Plage = WO.Range("A3:L" & DerLig)
Plage.Sort Key1:=Range("G3"), Order1:=xlAscending, Key2:=Range _
("I3"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers, _
DataOption2:=xlSortNormal
WO.Range("A5").AutoFilter Field:=7, Criteria1:=TextBox5
DerFiltre = Plage.SpecialCells(xlVisible).Columns(5).Find("*", , , , xlByColumns, xlPrevious).Row
'MsgBox DerLig
WO.ShowAllData
If WO.Cells(DerFiltre, 11) = "" Then
MsgBox "Ce matériel est en cours d'emprunt"
TextBox5.Value = ""
TextBox5.SetFocus
Exit Sub
End If
'** fin verif
End If
Me.designation = c.Offset(0, 3)
Me.constructeur = c.Offset(0, 2)
Me.modele = c.Offset(0, 4)
Me.numeroate = c.Offset(0, 0)
End If
End Sub