Bonjour à tous,

Je voudrais en fait adapter cette procédure à une google sheet.

La procédure sur Excel je l'affecte à un bouton sur lequel je clique pour faire un calcul.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Sub calcul()
 
 
Dim f As Long, r As Long, C As Long, J As Long
 
f = ActiveCell.Row
r = Cells(f, 3).Value
 
C = 0
J = 0
i = f
 
 
 
If Not IsEmpty(Cells(i - 1, 4)) Then
 
     If IsNumeric((Cells(i - 1, 4))) Then
 
 
           Do Until C + Cells(i, 4).Value >= r
           C = C + Cells(i, 4): Cells(f, 14) = C
           i = i - 1
           J = J + 1
           If Not IsNumeric(Cells(i, 4)) Then
           Exit Do
           End If
           Loop
 
 
           Cells(f, 18) = J
           X = f - J
           Cells(f, 19) = X
 
               If IsNumeric(Cells(X, 4)) Then
 
                  Cells(f, 15).Value = Cells(f, 14).Value + Cells(X, 4).Value
 
               Else
 
                  MsgBox "Données historiques insuffisantes"
                  Cells(f, 15) = Cells(f, 14) * (J + 1) / J
                  Cells(f, 11).Interior.Color = RGB(255, 165, 0)
               End If
 
           Cells(f, 14).EntireColumn.Hidden = False
           Cells(f, 15).EntireColumn.Hidden = False
           Cells(f, 16) = Cells(f, 3) / (Cells(f, 15) / (J + 1))
           Cells(f, 16).EntireColumn.Hidden = False
 
 
           Cells(f, 11) = Cells(f, 16)
 
      Else
 
           MsgBox "Données historiques insuffisantes"
 
           Cells(f, 11).Interior.Color = RGB(255, 165, 0)
           Cells(f, 11) = Cells(f, 3) / Cells(f, 4)
      End If
 
Else
 
    MsgBox "Données historiques insuffisantes"
    Cells(f, 11).Interior.Color = RGB(255, 165, 0)
    Cells(f, 11) = Cells(f, 3) / Cells(f, 4)
 
End If
 
 
 
End Sub