Bonjour à tous.
Dans le fichier ci-joint, je souhaite que certaines lignes soient copiées dans l'onglet Amalgame si la cellule H4 contient OUI mais que ces mêmes lignes soient copiées dans l'onglet journal des sorties si la même cellule H4 contient non. Mon code est le suivant :
Private Sub Copier_click()
Dim WsC As Worksheet
Dim DerLigC As Long, DerLigS As Long
Application.ScreenUpdating = False
With Worksheets("Générateur BCI")
If .Range("H4") = "OUI" Then
Set WsC = Worksheets("Amalgame")
DerLigS = .Range("Fond").End(xlUp).Row
For i = 16 To DerLigS
DerLigC = WsC.Range("D" & Rows.Count).End(xlUp).Row + 1
WsC.Range("G" & DerLigC) = .Range("B3") 'N° bon de commande interne
WsC.Range("A" & DerLigC) = .Range("P2") 'Date du jour
WsC.Range("D" & DerLigC) = .Range("B5") ' Bâtiment
WsC.Range("H" & DerLigC) = Range("D5") 'Demandeur
WsC.Range("E" & DerLigC) = .Range("D3") 'Service
WsC.Range("F" & DerLigC) = .Range("D4") 'Etage
WsC.Range("B" & DerLigC) = .Range("A" & i) 'N° article
WsC.Range("C" & DerLigC) = .Range("C" & i) 'Quantité
If .Range("H4") = "NON" Then
Set WsC = Worksheets("Journal des sorties")
DerLigS = .Range("Fond").End(xlUp).Row
For i = 16 To DerLigS
DerLigC = WsC.Range("D" & Rows.Count).End(xlUp).Row + 1
WsC.Range("K" & DerLigC) = .Range("B3") 'N° bon de commande interne
WsC.Range("A" & DerLigC) = .Range("P2") 'Date du jour
WsC.Range("H" & DerLigC) = .Range("B5") ' Bâtiment
WsC.Range("L" & DerLigC) = Range("D5") 'Demandeur
WsC.Range("I" & DerLigC) = .Range("D3") 'Service
WsC.Range("J" & DerLigC) = .Range("D4") 'Etage
WsC.Range("B" & DerLigC) = .Range("A" & i) 'N° article
WsC.Range("E" & DerLigC) = .Range("C" & i) 'Quantité
Next i
WsC.Activate
Set WsC = Nothing
Else
End If
End With
Application.ScreenUpdating = True
End Sub
Lorsque je lance la macro, j'obtiens une erreur de compilation (Variable de contrôle For déjà utilisée).
Le fichier excel joint en annexe est probablement plus parlant.
Bien cordialement,
Huggy.