1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| Dim nbdate, val As Integer
Dim Lstruc, Lmp, Lcaro, LequiV, LequiE, LequiO, Ltotal, C1, Cfin, nbC As Integer
Dim formule As Variant
Dim ws1, wsprix As Worksheet
_____________________________________________________________________________________________
Sub sauvgarde_prix()
' sauvgarde_prix
'
' Permets de sauvegarder les prix finals de chaque sous-ensemble pour suivre son évolution
Set ws1 = Worksheets("feuille 1")
Set wsprix = Worksheets("historique des prix")
' ici sont regoupés les coordonner des differents grandes parties.
' L pour ligne C pour colonne. t'as vue c'est simple
Lstruc = 5
Lmp = 116
Lcaro = 158
LequiV = 571
LequiE = 753
LequiO = 827
Ltotal = 869
C1 = 117
Cfin = 120
' nbC est le nombre de colonnes ou de produits
nbC = (Cfin - C1) + 1
' ici la formule permet de savoir combien de date on déjà était rentré.
' afin de bien faire le décalage
' "nbdate" est le nombre de date déjà existant
formule = "=COUNTA(A2:CA2)"
wsprix.Cells(1, 1).Formula = formule
nbdate = wsprix.Range("A1").Value
' le sous-programme "ecriture" est la partie où les donner son écrite
' il est séparé du programme initial pour faciliter l'écriture du code
ecriture
'autofit permet de rendre le tableau plus lisible
autofit
' le clear est là uniquement parce que c'est pas très joli une formule en plein milieu de donner
Range("A1").Clear
End Sub
_____________________________________________________________________________________________
Sub ecriture()
' fusion de cellules et écriture de la date d'aujourd'hui
wsprix.Select
wsprix.Range(wsprix.Cells(2, 2 + nbC * nbdate), wsprix.Cells(2, 1 + nbC + nbC * nbdate)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Selection.Style = "Sortie"
ActiveCell.Formula = Now
' retransmission des donnés
wsprix.Range(wsprix.Cells(3, 2 + nbC * nbdate), _
wsprix.Cells(3, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(1, C1), _
ws1.Cells(1, Cfin)).Value
wsprix.Range(wsprix.Cells(4, 2 + nbC * nbdate), _
wsprix.Cells(4, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(Lstruc, C1), _
ws1.Cells(Lstruc, Cfin)).Value
wsprix.Range(wsprix.Cells(5, 2 + nbC * nbdate), _
wsprix.Cells(5, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(Lmp, C1), _
ws1.Cells(Lmp, Cfin)).Value
wsprix.Range(wsprix.Cells(6, 2 + nbC * nbdate), _
wsprix.Cells(6, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(Lcaro, C1), _
ws1.Cells(Lcaro, Cfin)).Value
wsprix.Range(wsprix.Cells(7, 2 + nbC * nbdate), _
wsprix.Cells(7, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(LequiV, C1), _
ws1.Cells(LequiV, Cfin)).Value
wsprix.Range(wsprix.Cells(8, 2 + nbC * nbdate), _
wsprix.Cells(8, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(LequiE, C1), _
ws1.Cells(LequiE, Cfin)).Value
wsprix.Range(wsprix.Cells(9, 2 + nbC * nbdate), _
wsprix.Cells(9, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(LequiO, C1), _
ws1.Cells(LequiO, Cfin)).Value
wsprix.Range(wsprix.Cells(10, 2 + nbC * nbdate), _
wsprix.Cells(10, 1 + nbC + nbC * nbdate)).Formula = ws1.Range(ws1.Cells(Ltotal, C1), _
ws1.Cells(Ltotal, Cfin)).Value
End Sub
_____________________________________________________________________________________________
Sub autofit()
Range(Columns(2 + nbC * nbdate), Columns(1 + nbC + nbC * nbdate)).EntireColumn.autofit
End Sub |
Partager