erreur 1004
Débogage:
Sub test()
impFichMatos 17
End Sub
Sub impFichMatos(num_sejour As Long)
Dim shImpMat As Worksheet ', shMatSej As Worksheet, shMatPla As Worksheet
Set shImpMat = Worksheets("impress fich matos")
' Set shMatSej = Worksheets("matériel sur place")
' Set shMatPla = Worksheets("matériel séjour")
Dim materiel As Variant, sh As Worksheet
Dim i As Long, lig1 As Long, col1 As Long, lig2 As Long, derlig As Long, lig As Long
Dim catArt As String, pw As String
pw = "entrepot74"
materiel = Array("matériel séjour", "matériel sur place")
Application.ScreenUpdating = False
shImpMat.Unprotect Password:=pw
' nettoyer
Resize(shImpMat.Cells(Rows.Count, "B").End(xlUp).Row - 1, 4).ClearContents
col1 = num_sejour + 2
lig2 = 2
For i = 0 To 1
Set sh = Worksheets(materiel(i))
For lig1 = 3 To sh.Cells(Rows.Count, "B").End(xlUp).Row
If sh.Cells(lig1, col1) > 0 Then
If i = 0 Then
sh.Cells(lig1, 1).Resize(1, 2).Copy shImpMat.Cells(lig2, 1)
sh.Cells(lig1, col1).Copy shImpMat.Cells(lig2, 3)
lig2 = lig2 + 1
Else
catArt = sh.Cells(lig1, 1) & sh.Cells(lig1, 2)
derlig = shImpMat.Cells(Rows.Count, "B").End(xlUp).Row
For lig = 2 To derlig
If shImpMat.Cells(lig, 1) & shImpMat.Cells(lig, 2) = catArt Then Exit For
Next lig
If lig <= derlig Then
sh.Cells(lig1, col1).Copy shImpMat.Cells(lig, 4)
Else
sh.Cells(lig1, 1).Resize(1, 2).Copy shImpMat.Cells(lig, 1)
sh.Cells(lig1, col1).Copy shImpMat.Cells(lig, 4)
lig2 = lig2 + 1
End If
End If
End If
Next lig1
Next i
' trier
shImpMat.Sort.SortFields.Clear
shImpMat.Sort.SortFields.Add Key:=Range("A2:A500"), SortOn:=xlSortOnValues, Order:=xlAscending
shImpMat.Sort.SortFields.Add Key:=Range("B2:B500"), SortOn:=xlSortOnValues, Order:=xlAscending
With shImpMat.Sort
.SetRange Range("A1:D500")
.Header = xlYes
.Apply
End With
shImpMat.Protect Password:=pw
Application.ScreenUpdating = True
End Sub