Problème sur le code d'une macro

ericmaxime Messages postés 4 Date d'inscription vendredi 13 octobre 2006 Statut Membre Dernière intervention 15 octobre 2006 - 14 oct. 2006 à 17:36
ericmaxime Messages postés 4 Date d'inscription vendredi 13 octobre 2006 Statut Membre Dernière intervention 15 octobre 2006 - 15 oct. 2006 à 14:12
Bonjour,




Je suis entrain de travailler sur un code source vb







Il concerne une facture et les enregistrements sur une
feuille du classeur excel





 

La feuille se nomme « facture », et les
enregistrements de la facture se trouvent sur une feuille nommée « linstingV »)





 

Dans la cellule A13 de la feuille « facture » j’ai
rentré la formule « =(listingVA10)+1 »




De telle sorte que dans la macro est terminée la cellule A13
soit inncrémentée de 1





 

Seulement la cellule A13 de facture s’incrémente de 1 (elle
deviens après que la macro soit terminée =(listingV11)+1, donc elle ne bouge pas
et reste à la valeur 1





 

Et la cellule A10 de linstingV reste également à la même valeur
que la cellule en  dessous





 

C’est difficile à expliquer, voici le code source qui est un
peu brouillon et pas au point et donc pas terminée





 

Merci de m’aider.





Sub enregistrerlafacture()

'
myyear = Year(Range("G1"))

couryear = Year(Now)
If myyear = couryear Then GoTo suite Else MsgBox ("ATTENTION! bien vérifier d'avoir rentré la date correspondant à l'année en cours au format jj/mm/aaaa !")
Range("G1").ClearContents
Exit Sub
suite:

Style = vbOKCancel
Reponse = MsgBox("As-tu bien tout vérifié, parce qu'après c'est plus compliqué de modifier (il faut aller dans le listing). Si c'est bon, clique sur OK ", Style)
If Reponse = vbCancel Then Exit Sub

ActiveSheet.Unprotect
Worksheets("listingV").Select
Worksheets("listingV").Rows(10).Select
Selection.Insert

Range("A10:DC10").Select
With Selection.Interior
        .ColorIndex = 2
        .Pattern = xlGray16
        .PatternColorIndex = 37
        With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With

Range("A10").Select
Range("A10").Formula = "=MAX(A11:A5006)+1"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Range("A7").Select

    'Coordonnées:
    Range("A10").Formula = "=facture!f10"
    Range("B10").Formula = "=facture!G1"
    Range("C10").Formula = "=facture!B10"
    Range("D10").Formula = "=facture!E4"
    Range("E10").Formula = "=facture!E5"
    Range("F10").Formula = "=facture!E6"
    Range("F6").Formula = "=facture!G10"
    
    'Produit 1
    Range("H10").Formula = "=facture!A16"
    Range("I10").Formula = "=facture!B16"
    Range("J10").Formula = "=facture!C16"
    Range("K10").Formula = "=facture!D16"
    Range("L10").Formula = "=facture!E16"
    Range("M10").Formula = "=facture!F16"
    Range("N10").Formula = "=facture!G16"
    
    'Produit 2
    Range("O10").Formula = "=facture!A17"
    Range("P10").Formula = "=facture!B17"
    Range("Q10").Formula = "=facture!C17"
    Range("R10").Formula = "=facture!D17"
    Range("S10").Formula = "=facture!E17"
    Range("T10").Formula = "=facture!F17"
    Range("U10").Formula = "=facture!G17"
    
    
    
    Rows("10:10").EntireRow.AutoFit
    Worksheets("listingV").Rows(10).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues
 
    madate = Range("B10")
    Range("DD10") = Month(madate) * 1.1
    
    'selectionne la feuille des commandes
    Worksheets("facture").Select
    Range("G1").Select
    Range("G1") = Now
    
    Range("A1").Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    Exit Sub
Blème:
    MsgBox ("le date, c'est en chiffre STP, Pas en charabia!")
    Exit Sub
End Sub

3 réponses

cs_MPi Messages postés 3877 Date d'inscription mardi 19 mars 2002 Statut Membre Dernière intervention 17 août 2018 23
14 oct. 2006 à 19:13
Je ne vois rien qui parle de la cellule A13...

Par contre contre, je vois que tu places une formule en A10 (numéro incrémenté de 1)
"=MAX(A11:A5006)+1"

 puis tout de suite après, tu lui donnes une autre valeur
Range("A10").Formula = "=facture!f10"


???

MPi
0
ericmaxime Messages postés 4 Date d'inscription vendredi 13 octobre 2006 Statut Membre Dernière intervention 15 octobre 2006
14 oct. 2006 à 23:40
oui, il y a cette erreur, je l'ai modifiée
donc ça donne
Range("A10").Formula = "=facture!a13"

mais le problème persiste !
0
ericmaxime Messages postés 4 Date d'inscription vendredi 13 octobre 2006 Statut Membre Dernière intervention 15 octobre 2006
15 oct. 2006 à 14:12
pourtant le code source suivant dont je me suis basé fonctionne

Sub Enregistrer_Click()
On Error GoTo Blème

myyear = Year(Range("H5"))

couryear = Year(Now)
If myyear = couryear Then GoTo suite Else MsgBox ("ATTENTION! soit tu as rentré une date qui n'appartient pas à l'année en cours, soit tu n'as pas respecté le format de date (JJ/MM/AA), soit tu as oublié d'inscrire la date !")
Range("H5").ClearContents
Exit Sub
suite:

Style = vbOKCancel
Reponse = MsgBox("As-tu bien tout vérifié, parce qu'après c'est plus compliqué de modifier (il faut aller dans le listing). Si c'est bon, clique sur OK ", Style)
If Reponse = vbCancel Then Exit Sub

ActiveSheet.Unprotect
Worksheets("LISTING").Select
Worksheets("LISTING").Rows(3).Select
Selection.Insert
Range("A3:DC3").Select
With Selection.Interior
        .ColorIndex = 2
        .Pattern = xlGray16
        .PatternColorIndex = 37
        With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End With
   
    Range("A3").Select
Range("A3").Formula = "=MAX(A4:A5000)+1"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Range("A1").Select
    'Coordonnées:
    Range("B3").Formula = "=Enregistrer_commande!H5"
    Range("C3").Formula = "=Enregistrer_commande!J4"
    Range("D3").Formula = "=Enregistrer_commande!D8"
    Range("E3").Formula = "=Enregistrer_commande!D10"
    Range("F3").Formula = "=Enregistrer_commande!J8"
    Range("G3").Formula = "=Enregistrer_commande!J12"
    Range("H3").Formula = "=Enregistrer_commande!J10"
    Range("K3").Formula = "=Enregistrer_commande!H27"
    'produit 1:
    Range("L3").Formula = "=Enregistrer_commande!C15"
    Range("M3").Formula = "=Enregistrer_commande!B15"
    Range("N3").Formula = "=Enregistrer_commande!D15"
    Range("O3").Formula = "=Enregistrer_commande!E15"
    Range("P3").Formula = "=Enregistrer_commande!F15"
    Range("Q3").Formula = "=Enregistrer_commande!G15"
    Range("R3").Formula = "=Enregistrer_commande!H15"
    Range("S3").Formula = "=Enregistrer_commande!J15"
    'produit 2:
    Range("T3").Formula = "=Enregistrer_commande!C16"
    Range("U3").Formula = "=Enregistrer_commande!B16"
    Range("V3").Formula = "=Enregistrer_commande!D16"
    Range("W3").Formula = "=Enregistrer_commande!E16"
    Range("X3").Formula = "=Enregistrer_commande!F16"
    Range("Y3").Formula = "=Enregistrer_commande!G16"
    Range("Z3").Formula = "=Enregistrer_commande!H16"
    Range("AA3").Formula = "=Enregistrer_commande!J16"
    'produit 3:
    Range("AB3").Formula = "=Enregistrer_commande!C17"
    Range("AC3").Formula = "=Enregistrer_commande!B17"
    Range("AD3").Formula = "=Enregistrer_commande!D17"
    Range("AE3").Formula = "=Enregistrer_commande!E17"
    Range("AF3").Formula = "=Enregistrer_commande!F17"
    Range("AG3").Formula = "=Enregistrer_commande!G17"
    Range("AH3").Formula = "=Enregistrer_commande!H17"
    Range("AI3").Formula = "=Enregistrer_commande!J17"
    'produit 4:
    Range("AJ3").Formula = "=Enregistrer_commande!C18"
    Range("AK3").Formula = "=Enregistrer_commande!B18"
    Range("AL3").Formula = "=Enregistrer_commande!D18"
    Range("AM3").Formula = "=Enregistrer_commande!E18"
    Range("AN3").Formula = "=Enregistrer_commande!F18"
    Range("AO3").Formula = "=Enregistrer_commande!G18"
    Range("AP3").Formula = "=Enregistrer_commande!H18"
    Range("AQ3").Formula = "=Enregistrer_commande!J18"
    'produit 5:
    Range("AR3").Formula = "=Enregistrer_commande!C19"
    Range("AS3").Formula = "=Enregistrer_commande!B19"
    Range("AT3").Formula = "=Enregistrer_commande!D19"
    Range("AU3").Formula = "=Enregistrer_commande!E19"
    Range("AV3").Formula = "=Enregistrer_commande!F19"
    Range("AW3").Formula = "=Enregistrer_commande!G19"
    Range("AX3").Formula = "=Enregistrer_commande!H19"
    Range("AY3").Formula = "=Enregistrer_commande!J19"
    'produit 6:
    Range("AZ3").Formula = "=Enregistrer_commande!C20"
    Range("BA3").Formula = "=Enregistrer_commande!B20"
    Range("BB3").Formula = "=Enregistrer_commande!D20"
    Range("BC3").Formula = "=Enregistrer_commande!E20"
    Range("BD3").Formula = "=Enregistrer_commande!F20"
    Range("BE3").Formula = "=Enregistrer_commande!G20"
    Range("BF3").Formula = "=Enregistrer_commande!H20"
    Range("BG3").Formula = "=Enregistrer_commande!J20"
    'produit 7:
    Range("BH3").Formula = "=Enregistrer_commande!C21"
    Range("BI3").Formula = "=Enregistrer_commande!B21"
    Range("BJ3").Formula = "=Enregistrer_commande!D21"
    Range("BK3").Formula = "=Enregistrer_commande!E21"
    Range("BL3").Formula = "=Enregistrer_commande!F21"
    Range("BM3").Formula = "=Enregistrer_commande!G21"
    Range("BN3").Formula = "=Enregistrer_commande!H21"
    Range("BO3").Formula = "=Enregistrer_commande!J21"
   
    'produit 8:
    Range("BP3").Formula = "=Enregistrer_commande!C22"
    Range("BQ3").Formula = "=Enregistrer_commande!B22"
    Range("BR3").Formula = "=Enregistrer_commande!D22"
    Range("BS3").Formula = "=Enregistrer_commande!E22"
    Range("BT3").Formula = "=Enregistrer_commande!F22"
    Range("BU3").Formula = "=Enregistrer_commande!G22"
    Range("BV3").Formula = "=Enregistrer_commande!H22"
    Range("BW3").Formula = "=Enregistrer_commande!J22"
   
    'produit 9:
    Range("BX3").Formula = "=Enregistrer_commande!C23"
    Range("BY3").Formula = "=Enregistrer_commande!B23"
    Range("BZ3").Formula = "=Enregistrer_commande!D23"
    Range("CA3").Formula = "=Enregistrer_commande!E23"
    Range("CB3").Formula = "=Enregistrer_commande!F23"
    Range("CC3").Formula = "=Enregistrer_commande!G23"
    Range("CD3").Formula = "=Enregistrer_commande!H23"
    Range("CE3").Formula = "=Enregistrer_commande!J23"
    'produit 10:
    Range("CF3").Formula = "=Enregistrer_commande!C24"
    Range("CG3").Formula = "=Enregistrer_commande!B24"
    Range("CH3").Formula = "=Enregistrer_commande!D24"
    Range("CI3").Formula = "=Enregistrer_commande!E24"
    Range("CJ3").Formula = "=Enregistrer_commande!F24"
    Range("CK3").Formula = "=Enregistrer_commande!G24"
    Range("CL3").Formula = "=Enregistrer_commande!H24"
    Range("CM3").Formula = "=Enregistrer_commande!J24"
    'produit 11:
    Range("CN3").Formula = "=Enregistrer_commande!C25"
    Range("CO3").Formula = "=Enregistrer_commande!B25"
    Range("CP3").Formula = "=Enregistrer_commande!D25"
    Range("CQ3").Formula = "=Enregistrer_commande!E25"
    Range("CR3").Formula = "=Enregistrer_commande!F25"
    Range("CS3").Formula = "=Enregistrer_commande!G25"
    Range("CT3").Formula = "=Enregistrer_commande!H25"
    Range("CU3").Formula = "=Enregistrer_commande!J25"
    'produit 12:
    Range("CV3").Formula = "=Enregistrer_commande!C26"
    Range("CW3").Formula = "=Enregistrer_commande!B26"
    Range("CX3").Formula = "=Enregistrer_commande!D26"
    Range("CY3").Formula = "=Enregistrer_commande!E26"
    Range("CZ3").Formula = "=Enregistrer_commande!F26"
    Range("DA3").Formula = "=Enregistrer_commande!G26"
    Range("DB3").Formula = "=Enregistrer_commande!H26"
    Range("DC3").Formula = "=Enregistrer_commande!J26"
   
    Rows("3:3").EntireRow.AutoFit
    Worksheets("LISTING").Rows(3).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues
   
    Range("A3:B3").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=SI(ET($I3<>"""";$J3<>"""");VRAI;FAUX)"
    With Selection.FormatConditions(1).Interior
        .ColorIndex = 35
        .Pattern = xlSolid
    End With
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=SI(ET(MAINTENANT()-$B3>25;$I3="""");VRAI;FAUX)"
    With Selection.FormatConditions(2).Interior
        .ColorIndex = 36
        .Pattern = xlSolid
    End With
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=SI(ET(MAINTENANT()-$I3>10;$J3="""";$I3<>"""");VRAI;FAUX)"
    With Selection.FormatConditions(3).Interior
        .ColorIndex = 44
        .Pattern = xlSolid
    End With
   
    madate = Range("B3")
    Range("DD3") = Month(madate) * 1.1
   
    'selectionne la feuille des commandes
    Worksheets("Enregistrer_commande").Select
    Range("H5").Select
    Range("H5") = Now
   
    Range("J4").ClearContents
    Range("D8:D10").ClearContents
    Range("G8:G10").ClearContents
    Range("J8:J12").ClearContents
    Range("I15:J26").ClearContents
    Range("B15:G26").ClearContents
   
   
    Range("A1").Select
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    Exit Sub
Blème:
    MsgBox ("le date, c'est en chiffre STP, Pas en charabia!")
    Exit Sub
End Sub
0
Rejoignez-nous