Sub Rech_art()
Dim pl As Long
Dim art1, art2 As Variant
Sheets("Stoks").Activate
art1 = Cells(2, 10)
pl = 5
Cherch:
art2 = Cells(pl, 1)
If IsEmpty(art2) Then
MsgBox "Article " & art1 & " non trouvé. Il a été ajouté en fin de fichier."
'Range(Cells(pl, 1), Cells(pl, 1)).Select
Rows(pl).Select
Selection.RowHeight = 17
Range(Cells(pl - 1, 1), Cells(pl - 1, 6)).Select
Selection.Copy
Range(Cells(pl, 1), Cells(pl, 1)).Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Cells(pl, 1) = art1
Cells(pl, 3) = ""
Cells(pl, 4) = ""
Cells(pl, 6) = ""
Exit Sub
Else
If art2 = art1 Then
Range(Cells(pl, 1), Cells(pl, 1)).Select
Exit Sub
Else
If art2 > art1 Then
Rows(pl).Select
Selection.Insert Shift:=xlDown
Selection.RowHeight = 17
Range(Cells(pl - 1, 1), Cells(pl - 1, 5)).Select
Selection.Copy
Range(Cells(pl, 1), Cells(pl, 1)).Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=False
Cells(pl, 1) = art1
Cells(pl, 3) = ""
Cells(pl, 4) = ""
Cells(pl, 6) = ""
MsgBox "Article " & art1 & " non trouvé. Il a été ajouté entre 2 articles existants."
Range(Cells(pl, 1), Cells(pl, 1)).Select
Exit Sub
End If
pl = pl + 1
GoTo Cherch
End If
End If
End Sub
Partager