IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Modification d'une variable durant l'exécution d'un code


Sujet :

Macros et VBA Excel

  1. #1
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut Modification d'une variable durant l'exécution d'un code
    Bonjour,
    Est-il possible de modifier une variable durant l'exécution d'un code.

    Par exemple, si j'ai une boucle:

    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
     
    Dim i As Integer, MaVariable As Long, MonResultat As Long
     
    MaVariable = Range("A1").Value
     
    i = 2
    While i <= 1000
     
    MonResultat = MaVariable + i
     
    Range("A" & i).Value = MonResultat
     
    i = i + 1
     
    Wend
    Existe-t-il un moyen pour pouvoir intervenir sur MaVariable durant le déroulement de la macro?

    Un UserForm ou une InPutBox qui resterait ouvert durant le code et dans lequel je pourrais inscrire MaVariable = (ce que je veux) à tout moment? Ou qui se rafraichirait à chaque boucle pour m'offrir cette possibilité (sans que le code soit trop ralenti?

    Ou tout autre solution.


    Je vous remercie pour tout aide!!!!!!!!

  2. #2
    Membre Expert Avatar de Transitoire
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Décembre 2017
    Messages
    733
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Décembre 2017
    Messages : 733
    Par défaut
    Bonjour, je comprend pas?
    Vous avez une boucle, elle va mettre peut être 2 secondes à s'effectuer et vous dites:
    Existe-t-il un moyen pour pouvoir intervenir sur MaVariable durant le déroulement de la macro?
    Faudrais vous entrainer avec Lucky luke?
    Vous pouvez installer dans la boucle un MsgBox ou un inputBox, mais si vous avez 900 passages, bonjour l'angoisse.
    Pardonnez moi, mais je ne vois pas trop ce que vous pourriez faire compte tenu du fait que même un userform non modal; ne vous laisserai pas le temps de réaction!!!!
    Mais je peut me tromper?
    Cordialement

  3. #3
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut
    La boucle est en fait un peu plus longue (plusieurs milliers de lignes), j'ai simplifié, et la modification que je ferai sera à prendre en compte dans le calcul n lignes plus loin

    Dans le Userform (par exemple), j'aurai un textbox fixe dans lequel je pourrais rentrer une valeur x qui modifierait le calcul n lignes plus loin, le temps que mon action soit prise en compte.

    J'ai mis un Userform avec mais si je clic dedans, l'affichage se fige et le calcul continue à tourner sans que je ne puisse plus intervenir jusqu'à la fin du code.

    Même sans cliquer, l'affichage se fige

    Le code en question si c'est plus clair:

    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
    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
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    Option Explicit
    Sub GRAVIT()
     
    Application.Volatile
     
    Range("C9").Clear
     
    Dim XtempsX_debut As Single
       Dim XdureeX As Single
     
       XtempsX_debut = Timer
      Range("B7").Value = Format(XtempsX_debut / 86400, "hh:mm:ss")
     
     
     Pas = Range("B17").Value
     MA = Range("A2").Value
     MB = Range("B2").Value
     MC = Range("C2").Value
     G = 6.67408 ^ 10 - 11
     
     xA = Range("B27").Value
     yA = Range("B28").Value
     zA = Range("B29").Value
     xB = Range("B31").Value
     yB = Range("B32").Value
     zB = Range("B33").Value
     xC = Range("B35").Value
     yC = Range("B36").Value
     zC = Range("B37").Value
     vxA = Range("B41").Value
     vyA = Range("B42").Value
     vzA = Range("B43").Value
     vxB = Range("B45").Value
     vyB = Range("B46").Value
     vzB = Range("B47").Value
     vxC = Range("B49").Value
     vyC = Range("B50").Value
     vzC = Range("B51").Value
     
     
     
     
    If Range("A15").Value = "OK" Then
     
     UserForm1.Show vbModeless
     
     
    Range("D2:AD100000").Clear
    Range("B8:B9").Clear
    Range("B11").ClearContents
     
    i = 2
    jusk = Range("B10").Value
    While i = 2
     
     
     
     Range("D" & i).Select
     
     
     
    Range("B11").Value = (ActiveCell.Row) / jusk * 100
     
    Application.ScreenUpdating = False
     
    Dim temps_debut As Single
       Dim duree As Single
     
     
       temps_debut = Timer
     
     
     
     
     
     
     
    axA = G * (((MB * (xB - xA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    ayA = G * (((MB * (yB - yA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - yA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    azA = G * (((MB * (zB - zA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (zC - zA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    axB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    ayB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    azB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    axC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    ayC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    azC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
     
     
     
     Range("V" & i).Value = axA
     Range("W" & i).Value = ayA
     Range("X" & i).Value = azA
     Range("Y" & i).Value = axB
     Range("Z" & i).Value = ayB
     Range("AA" & i).Value = azB
     Range("AB" & i).Value = axC
     Range("AC" & i).Value = ayC
     Range("AD" & i).Value = azC
     
    DEMIT = Range("AE" & i).Value
     
     
     
    vxA = vxA + axA * DEMIT
    vyA = vyA + ayA * DEMIT
    vzA = vzA + azA * DEMIT
    vxB = vxB + axB * DEMIT
    vyB = vyB + ayB * DEMIT
    vzB = vzB + azB * DEMIT
    vxC = vxC + axC * DEMIT
    vyC = vyC + ayC * DEMIT
    vzC = vzC + azC * DEMIT
     
     
     
     Range("M" & i).Value = vxA
     Range("N" & i).Value = vyA
     Range("O" & i).Value = vzA
     Range("P" & i).Value = vxB
     Range("Q" & i).Value = vyB
     Range("R" & i).Value = vzB
     Range("S" & i).Value = vxC
     Range("T" & i).Value = vyC
     Range("U" & i).Value = vzC
     
     UserForm1.Repaint
     
     UserForm1.Label10.Caption = vxA
     UserForm1.Label11.Caption = vyA
     UserForm1.Label12.Caption = vzA
     UserForm1.Label13.Caption = vxB
     UserForm1.Label14.Caption = vyB
     UserForm1.Label15.Caption = vzB
     UserForm1.Label16.Caption = vxC
     UserForm1.Label17.Caption = vyC
     UserForm1.Label18.Caption = vzC
     
     If UserForm1.CommandButton1.Value = "Vrai" Then
     Unload UserForm1
     Exit Sub
     Else
     
     
     T = Range("AE" & i + 1).Value
     
     xA = xA + vxA * T
     yA = yA + vyA * T
     zA = zA + vzA * T
     xB = xB + vxB * T
     yB = yB + vyB * T
     zB = zB + vzB * T
     xC = xC + vxC * T
     yC = yC + vyC * T
     zC = zC + vzC * T
     
     Application.ScreenUpdating = True
     
     Range("D" & i).Value = xA
     Range("E" & i).Value = yA
     Range("F" & i).Value = zA
     Range("G" & i).Value = xB
     Range("H" & i).Value = yB
     Range("I" & i).Value = zB
     Range("J" & i).Value = xC
     Range("K" & i).Value = yC
     Range("L" & i).Value = zC
     
     
     
     xA = Range("D" & i).Value
     yA = Range("E" & i).Value
     zA = Range("F" & i).Value
     xB = Range("G" & i).Value
     yB = Range("H" & i).Value
     zB = Range("I" & i).Value
     xC = Range("J" & i).Value
     yC = Range("K" & i).Value
     zC = Range("L" & i).Value
     
     
     
     
       duree = Timer - temps_debut
     
     
     
     
       Range("B8").Value = Format(duree / 86400, "hh:mm:ss,ms")
       Range("B9").Value = Format(duree * jusk / 86400, "hh:mm:ss,ms")
     
     Application.ScreenUpdating = False
     
     
     
      i = i + 1
     
      End If
     
      Wend
     
      j = i
     
    jusk = Range("B10").Value
    While j <= jusk
     
     
     Range("D" & j).Select
     
     
       Range("B11").Value = (ActiveCell.Row) / jusk * 100
     
    Application.ScreenUpdating = False
     
     
    axA = G * (((MB * (xB - xA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    ayA = G * (((MB * (yB - yA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - yA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    azA = G * (((MB * (zB - zA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (zC - zA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    axB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    ayB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    azB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    axC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    ayC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    azC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
     
     Range("V" & j).Value = axA
     Range("W" & j).Value = ayA
     Range("X" & j).Value = azA
     Range("Y" & j).Value = axB
     Range("Z" & j).Value = ayB
     Range("AA" & j).Value = azB
     Range("AB" & j).Value = axC
     Range("AC" & j).Value = ayC
     Range("AD" & j).Value = azC
     
    DEMIT = Range("AE" & j).Value
     
    vxA = vxA + axA * DEMIT
    vyA = vyA + ayA * DEMIT
    vzA = vzA + azA * DEMIT
    vxB = vxB + axB * DEMIT
    vyB = vyB + ayB * DEMIT
    vzB = vzB + azB * DEMIT
    vxC = vxC + axC * DEMIT
    vyC = vyC + ayC * DEMIT
    vzC = vzC + azC * DEMIT
     
     Range("M" & j).Value = vxA
     Range("N" & j).Value = vyA
     Range("O" & j).Value = vzA
     Range("P" & j).Value = vxB
     Range("Q" & j).Value = vyB
     Range("R" & j).Value = vzB
     Range("S" & j).Value = vxC
     Range("T" & j).Value = vyC
     Range("U" & j).Value = vzC
     
     UserForm1.Repaint
     
     UserForm1.Label10.Caption = vxA
     UserForm1.Label11.Caption = vyA
     UserForm1.Label12.Caption = vzA
     UserForm1.Label13.Caption = vxB
     UserForm1.Label14.Caption = vyB
     UserForm1.Label15.Caption = vzB
     UserForm1.Label16.Caption = vxC
     UserForm1.Label17.Caption = vyC
     UserForm1.Label18.Caption = vzC
     
     If UserForm1.CommandButton1.Value = "Vrai" Then
     Unload UserForm1
     Exit Sub
     Else
     
     T = Range("AE" & j + 1).Value
     
     xA = xA + vxA * T
     yA = yA + vyA * T
     zA = zA + vzA * T
     xB = xB + vxB * T
     yB = yB + vyB * T
     zB = zB + vzB * T
     xC = xC + vxC * T
     yC = yC + vyC * T
     zC = zC + vzC * T
     
     Application.ScreenUpdating = True
     
     Range("D" & j).Value = xA
     Range("E" & j).Value = yA
     Range("F" & j).Value = zA
     Range("G" & j).Value = xB
     Range("H" & j).Value = yB
     Range("I" & j).Value = zB
     Range("J" & j).Value = xC
     Range("K" & j).Value = yC
     Range("L" & j).Value = zC
     
     Application.ScreenUpdating = False
     
     j = j + 1
     
     
     
     
     End If
     
     Wend
     
     
     XdureeX = Timer - XtempsX_debut
     
     
     
       Range("C9").Value = Format(XdureeX / 86400, "hh:mm:ss,ms")
     
     
     
     
     
    Else
     
     
    MsgBox Range("A10").Value & " doit être " & Range("A11").Value & " " & Range("A12").Value
    Exit Sub
     
     
    End If
     
     
    ThisWorkbook.Save
     
     
    End Sub
    Je cherche donc à tracer les trajectoires de 3 corps A; B; C sont une formule de la gravitation.

    Je cherche à intervenir sur les vitesses des 3 corps durant l'exécution du code (qui peut se dérouler sur 10 000 lignes, ce qui prend ~20 minutes, avec une boucle à ~120 millisecondes)

  4. #4
    Membre Expert
    Avatar de pijaku
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    1 817
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Août 2010
    Messages : 1 817
    Billets dans le blog
    10
    Par défaut
    Bonjour,

    Si tu connais à l'avance les indices de lignes ou ta variable doit changer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Sub Macro2()
    Dim i As Long, mavariable As String
       mavariable = "toto"
       For i = 1 To 1000000
          If i Mod 200000 = 0 Then
             mavariable = InputBox("Saisie à l'indice de boucle : " & i, "Nouvelle variable", mavariable)
          End If
       Next
    End Sub

  5. #5
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut
    Non, malheureusement, c'est en réaction à l'évolution des résultats que je souhaite intervenir sur mes variable.

  6. #6
    Membre Expert
    Avatar de pijaku
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    1 817
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Août 2010
    Messages : 1 817
    Billets dans le blog
    10
    Par défaut
    c'est en réaction à l'évolution des résultats
    Est-ce que cette évolution est "prévisible"?
    Si oui, tu dois pouvoir déterminer à quel moment elle aura lieu.
    Et donc, via un test if, proposer une saisie.


    Si non, ça me semble plus que compromis ton histoire.

  7. #7
    Membre Expert
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 266
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 2 266
    Par défaut
    Bonjour à tous,

    Met un DoEvents dans ta boucle pour pouvoir tenir compte d'une modif d'un textbox.
    Si tu veux pouvoir faire cette modif dans une cellule il faut mettre ton UF en non modal.
    Accessoirement Application.Volatile ne sert que pour les Function, pas les Sub. Et il faut faut le faire avec raison.
    eric

  8. #8
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut
    Le but est de contrarier l'accélération de la force centrifuge entre le corps qui les expulse d'une trajectoire en orbite, donc à la limite, la condition que je pourrais utiliser serait un taux d'éloignement trop important qui vient en contradiction avec la force d'attraction.

    En l'absence de tout autre possibilité ce pourrait être un recours.

    Voilà où j'en suis:

    Le code:

    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
    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
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    Option Explicit
    Sub GRAVIT()
     
    Application.Volatile
     
     
    Range("C9").Clear
     
     
     Pas = Range("B17").Value
     MA = Range("A2").Value
     MB = Range("B2").Value
     MC = Range("C2").Value
     G = 6.67408 ^ 10 - 11
     
     xA = Range("B27").Value
     yA = Range("B28").Value
     zA = Range("B29").Value
     xB = Range("B31").Value
     yB = Range("B32").Value
     zB = Range("B33").Value
     xC = Range("B35").Value
     yC = Range("B36").Value
     zC = Range("B37").Value
     vxA = Range("B41").Value
     vyA = Range("B42").Value
     vzA = Range("B43").Value
     vxB = Range("B45").Value
     vyB = Range("B46").Value
     vzB = Range("B47").Value
     vxC = Range("B49").Value
     vyC = Range("B50").Value
     vzC = Range("B51").Value
     
     
     UserForm1.Label19.Caption = Range("B41").Value
     UserForm1.Label20.Caption = Range("B42").Value
     UserForm1.Label21.Caption = Range("B43").Value
     UserForm1.Label22.Caption = Range("B45").Value
     UserForm1.Label23.Caption = Range("B46").Value
     UserForm1.Label24.Caption = Range("B47").Value
     UserForm1.Label25.Caption = Range("B49").Value
     UserForm1.Label26.Caption = Range("B50").Value
     UserForm1.Label27.Caption = Range("B51").Value
     
     
     
     
    If Range("A15").Value = "OK" Then
     
     UserForm1.Show vbModeless
     
     Dim XtempsX_debut As Single
       Dim XdureeX As Single
     
       XtempsX_debut = Timer
      Range("B7").Value = Format(XtempsX_debut / 86400, "hh:mm:ss")
     
     
    Range("D2:AD100000").Clear
    Range("B8:B9").Clear
    Range("B11").ClearContents
     
    i = 2
    jusk = Range("B10").Value
    While i = 2
     
     
     
     
     
     Range("D" & i).Select
     
     
     
     
     
    Range("B11").Value = (ActiveCell.Row) / jusk * 100
     
    Application.ScreenUpdating = False
     
    Dim temps_debut As Single
       Dim duree As Single
     
     
       temps_debut = Timer
     
     
     
    axA = G * (((MB * (xB - xA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    ayA = G * (((MB * (yB - yA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - yA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    azA = G * (((MB * (zB - zA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (zC - zA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    axB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    ayB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    azB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    axC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    ayC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    azC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
     
     
     
     
     Range("V" & i).Value = axA
     Range("W" & i).Value = ayA
     Range("X" & i).Value = azA
     Range("Y" & i).Value = axB
     Range("Z" & i).Value = ayB
     Range("AA" & i).Value = azB
     Range("AB" & i).Value = axC
     Range("AC" & i).Value = ayC
     Range("AD" & i).Value = azC
     
    DEMIT = Range("AE" & i).Value
     
     
    vxA = vxA + axA * DEMIT
    vyA = vyA + ayA * DEMIT
    vzA = vzA + azA * DEMIT
    vxB = vxB + axB * DEMIT
    vyB = vyB + ayB * DEMIT
    vzB = vzB + azB * DEMIT
    vxC = vxC + axC * DEMIT
    vyC = vyC + ayC * DEMIT
    vzC = vzC + azC * DEMIT
     
     
     Range("M" & i).Value = vxA
     Range("N" & i).Value = vyA
     Range("O" & i).Value = vzA
     Range("P" & i).Value = vxB
     Range("Q" & i).Value = vyB
     Range("R" & i).Value = vzB
     Range("S" & i).Value = vxC
     Range("T" & i).Value = vyC
     Range("U" & i).Value = vzC
     
     UserForm1.Repaint
     
     UserForm1.Label10.Caption = vxA
     UserForm1.Label11.Caption = vyA
     UserForm1.Label12.Caption = vzA
     UserForm1.Label13.Caption = vxB
     UserForm1.Label14.Caption = vyB
     UserForm1.Label15.Caption = vzB
     UserForm1.Label16.Caption = vxC
     UserForm1.Label17.Caption = vyC
     UserForm1.Label18.Caption = vzC
     
     
     
     SignAntexA = UserForm1.Label28.Caption
     SignAnteyA = UserForm1.Label29.Caption
     SignAntezA = UserForm1.Label30.Caption
     SignAntexB = UserForm1.Label31.Caption
     SignAnteyB = UserForm1.Label32.Caption
     SignAntezB = UserForm1.Label33.Caption
     SignAntexC = UserForm1.Label34.Caption
     SignAnteyC = UserForm1.Label35.Caption
     SignAntezC = UserForm1.Label36.Caption
     
     
    If vxA - Range("B41").Value > 0 Then
     UserForm1.Label28.Caption = "+"
     Else
     UserForm1.Label28.Caption = "-"
     End If
     
     
     If vyA - Range("B42").Value > 0 Then
     UserForm1.Label29.Caption = "+"
     Else
     UserForm1.Label29.Caption = "-"
      End If
     
     
     If vzA - Range("B43").Value > 0 Then
     UserForm1.Label30.Caption = "+"
     Else
     UserForm1.Label30.Caption = "-"
      End If
     
     
     If vxB - Range("B45").Value > 0 Then
     UserForm1.Label31.Caption = "+"
     Else
     UserForm1.Label31.Caption = "-"
     End If
     
     
     If vyB - Range("B46").Value > 0 Then
     UserForm1.Label32.Caption = "+"
     Else
     UserForm1.Label32.Caption = "-"
      End If
     
     
     If vzB - Range("B47").Value > 0 Then
     UserForm1.Label33.Caption = "+"
     Else
     UserForm1.Label33.Caption = "-"
     End If
     
     
     If vxC - Range("B49").Value > 0 Then
     UserForm1.Label34.Caption = "+"
     Else
     UserForm1.Label34.Caption = "-"
     End If
     
     
     If vyC - Range("B50").Value > 0 Then
     UserForm1.Label35.Caption = "+"
     Else
     UserForm1.Label35.Caption = "-"
      End If
     
     
     If vzC - Range("B51").Value > 0 Then
     UserForm1.Label36.Caption = "+"
     Else
     UserForm1.Label36.Caption = "-"
     End If
     
     
     
     
     
     T = Range("AE" & i + 1).Value
     
     xA = xA + vxA * T
     yA = yA + vyA * T
     zA = zA + vzA * T
     xB = xB + vxB * T
     yB = yB + vyB * T
     zB = zB + vzB * T
     xC = xC + vxC * T
     yC = yC + vyC * T
     zC = zC + vzC * T
     
     Application.ScreenUpdating = True
     
     Range("D" & i).Value = xA
     Range("E" & i).Value = yA
     Range("F" & i).Value = zA
     Range("G" & i).Value = xB
     Range("H" & i).Value = yB
     Range("I" & i).Value = zB
     Range("J" & i).Value = xC
     Range("K" & i).Value = yC
     Range("L" & i).Value = zC
     
     
     
     xA = Range("D" & i).Value
     yA = Range("E" & i).Value
     zA = Range("F" & i).Value
     xB = Range("G" & i).Value
     yB = Range("H" & i).Value
     zB = Range("I" & i).Value
     xC = Range("J" & i).Value
     yC = Range("K" & i).Value
     zC = Range("L" & i).Value
     
     
     
     
       duree = Timer - temps_debut
     
     
     
     
       Range("B8").Value = Format(duree / 86400, "hh:mm:ss,ms")
       Range("B9").Value = Format(duree * jusk / 86400, "hh:mm:ss,ms")
     
     Application.ScreenUpdating = False
     
     
     
      i = i + 1
     
     
     
      Wend
     
      j = i
     
    jusk = Range("B10").Value
    While j <= jusk
     
     
     
     Range("D" & j).Select
     
     
       Range("B11").Value = (ActiveCell.Row) / jusk * 100
     
    Application.ScreenUpdating = False
     
     
    axA = G * (((MB * (xB - xA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    ayA = G * (((MB * (yB - yA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - yA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    azA = G * (((MB * (zB - zA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (zC - zA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    axB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    ayB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    azB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    axC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    ayC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    azC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
     
     Range("V" & j).Value = axA
     Range("W" & j).Value = ayA
     Range("X" & j).Value = azA
     Range("Y" & j).Value = axB
     Range("Z" & j).Value = ayB
     Range("AA" & j).Value = azB
     Range("AB" & j).Value = axC
     Range("AC" & j).Value = ayC
     Range("AD" & j).Value = azC
     
    DEMIT = Range("AE" & j).Value
     
    vxA = vxA + axA * DEMIT
    vyA = vyA + ayA * DEMIT
    vzA = vzA + azA * DEMIT
    vxB = vxB + axB * DEMIT
    vyB = vyB + ayB * DEMIT
    vzB = vzB + azB * DEMIT
    vxC = vxC + axC * DEMIT
    vyC = vyC + ayC * DEMIT
    vzC = vzC + azC * DEMIT
     
     Range("M" & j).Value = vxA
     Range("N" & j).Value = vyA
     Range("O" & j).Value = vzA
     Range("P" & j).Value = vxB
     Range("Q" & j).Value = vyB
     Range("R" & j).Value = vzB
     Range("S" & j).Value = vxC
     Range("T" & j).Value = vyC
     Range("U" & j).Value = vzC
     
     UserForm1.Repaint
     
     UserForm1.Label10.Caption = vxA
     UserForm1.Label11.Caption = vyA
     UserForm1.Label12.Caption = vzA
     UserForm1.Label13.Caption = vxB
     UserForm1.Label14.Caption = vyB
     UserForm1.Label15.Caption = vzB
     UserForm1.Label16.Caption = vxC
     UserForm1.Label17.Caption = vyC
     UserForm1.Label18.Caption = vzC
     
      SignAntexA = UserForm1.Label28.Caption
     SignAnteyA = UserForm1.Label29.Caption
     SignAntezA = UserForm1.Label30.Caption
     SignAntexB = UserForm1.Label31.Caption
     SignAnteyB = UserForm1.Label32.Caption
     SignAntezB = UserForm1.Label33.Caption
     SignAntexC = UserForm1.Label34.Caption
     SignAnteyC = UserForm1.Label35.Caption
     SignAntezC = UserForm1.Label36.Caption
     
     
    If vxA - Range("B41").Value > 0 Then
     UserForm1.Label28.Caption = "+"
     Else
     UserForm1.Label28.Caption = "-"
     End If
    If SignAntexA <> UserForm1.Label28.Caption Then
     UserForm1.Label28.ForeColor = RGB(255, 0, 0)
     End If
     
     If vyA - Range("B42").Value > 0 Then
     UserForm1.Label29.Caption = "+"
     Else
     UserForm1.Label29.Caption = "-"
      End If
    If SignAnteyA <> UserForm1.Label29.Caption Then
     UserForm1.Label29.ForeColor = RGB(255, 0, 0)
     End If
     
     If vzA - Range("B43").Value > 0 Then
     UserForm1.Label30.Caption = "+"
     Else
     UserForm1.Label30.Caption = "-"
      End If
    If SignAntezA <> UserForm1.Label30.Caption Then
     UserForm1.Label30.ForeColor = RGB(255, 0, 0)
     End If
     
     If vxB - Range("B45").Value > 0 Then
     UserForm1.Label31.Caption = "+"
     Else
     UserForm1.Label31.Caption = "-"
     End If
    If SignAntexB <> UserForm1.Label31.Caption Then
     UserForm1.Label31.ForeColor = RGB(255, 0, 0)
     End If
     
     If vyB - Range("B46").Value > 0 Then
     UserForm1.Label32.Caption = "+"
     Else
     UserForm1.Label32.Caption = "-"
      End If
    If SignAnteyB <> UserForm1.Label32.Caption Then
     UserForm1.Label32.ForeColor = RGB(255, 0, 0)
     End If
     
     If vzB - Range("B47").Value > 0 Then
     UserForm1.Label33.Caption = "+"
     Else
     UserForm1.Label33.Caption = "-"
     End If
    If SignAntezB <> UserForm1.Label33.Caption Then
     UserForm1.Label33.ForeColor = RGB(255, 0, 0)
     End If
     
     If vxC - Range("B49").Value > 0 Then
     UserForm1.Label34.Caption = "+"
     Else
     UserForm1.Label34.Caption = "-"
     End If
    If SignAntexC <> UserForm1.Label34.Caption Then
     UserForm1.Label34.ForeColor = RGB(255, 0, 0)
     End If
     
     If vyC - Range("B50").Value > 0 Then
     UserForm1.Label35.Caption = "+"
     Else
     UserForm1.Label35.Caption = "-"
      End If
    If SignAnteyC <> UserForm1.Label35.Caption Then
     UserForm1.Label35.ForeColor = RGB(255, 0, 0)
     End If
     
     If vzC - Range("B51").Value > 0 Then
     UserForm1.Label36.Caption = "+"
     Else
     UserForm1.Label36.Caption = "-"
     End If
    If SignAntezC <> UserForm1.Label36.Caption Then
     UserForm1.Label36.ForeColor = RGB(255, 0, 0)
     End If
     
     
     
     
     
     T = Range("AE" & j + 1).Value
     
     xA = xA + vxA * T
     yA = yA + vyA * T
     zA = zA + vzA * T
     xB = xB + vxB * T
     yB = yB + vyB * T
     zB = zB + vzB * T
     xC = xC + vxC * T
     yC = yC + vyC * T
     zC = zC + vzC * T
     
     Application.ScreenUpdating = True
     
     Range("D" & j).Value = xA
     Range("E" & j).Value = yA
     Range("F" & j).Value = zA
     Range("G" & j).Value = xB
     Range("H" & j).Value = yB
     Range("I" & j).Value = zB
     Range("J" & j).Value = xC
     Range("K" & j).Value = yC
     Range("L" & j).Value = zC
     
     Application.ScreenUpdating = False
     
     j = j + 1
     
     
     
     
     
     Wend
     
     
     XdureeX = Timer - XtempsX_debut
     
     
     
     
       Range("C9").Value = Format(XdureeX / 86400, "hh:mm:ss,ms")
     
     
     
    Else
     
     
    MsgBox Range("A10").Value & " doit être " & Range("A11").Value & " " & Range("A12").Value
    Exit Sub
     
     
    End If
     
     
    ThisWorkbook.Save
     
     
    End Sub
    La capture écran:

    Nom : 2018-10-30 14_05_06-UserForm1.png
Affichages : 215
Taille : 150,2 Ko

    Donc est-il possible de rentrer des valeur dans le textbox du USF?

    Si une autre méthode est à préconiser, je prends (à part l'invitation conditionnelle, que je réserve en dernier recours).

    Merci

  9. #9
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut
    Avec ce code:

    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
    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
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    Option Explicit
    Sub GRAVIT()
     
    Application.Volatile
     
    Range("C9").Clear
     
     
     Pas = Range("B17").Value
     MA = Range("A2").Value
     MB = Range("B2").Value
     MC = Range("C2").Value
     G = 6.67408 ^ 10 - 11
     
     xA = Range("B27").Value
     yA = Range("B28").Value
     zA = Range("B29").Value
     xB = Range("B31").Value
     yB = Range("B32").Value
     zB = Range("B33").Value
     xC = Range("B35").Value
     yC = Range("B36").Value
     zC = Range("B37").Value
     vxA = Range("B41").Value
     vyA = Range("B42").Value
     vzA = Range("B43").Value
     vxB = Range("B45").Value
     vyB = Range("B46").Value
     vzB = Range("B47").Value
     vxC = Range("B49").Value
     vyC = Range("B50").Value
     vzC = Range("B51").Value
     
     
     UserForm1.Label19.Caption = Range("B41").Value
     UserForm1.Label20.Caption = Range("B42").Value
     UserForm1.Label21.Caption = Range("B43").Value
     UserForm1.Label22.Caption = Range("B45").Value
     UserForm1.Label23.Caption = Range("B46").Value
     UserForm1.Label24.Caption = Range("B47").Value
     UserForm1.Label25.Caption = Range("B49").Value
     UserForm1.Label26.Caption = Range("B50").Value
     UserForm1.Label27.Caption = Range("B51").Value
     
     
     
     
    If Range("A15").Value = "OK" Then
     
     UserForm1.Show vbModeless
     
     Dim XtempsX_debut As Single
       Dim XdureeX As Single
     
       XtempsX_debut = Timer
      Range("B7").Value = Format(XtempsX_debut / 86400, "hh:mm:ss")
     
     
    Range("D2:AD100000").Clear
    Range("B8:B9").Clear
    Range("B11").ClearContents
     
    i = 2
    jusk = Range("B10").Value
    While i = 2
     
     
    Range("D" & i).Select
     
     
     
    Range("B11").Value = (ActiveCell.Row) / jusk * 100
     
    Application.ScreenUpdating = False
     
    Dim temps_debut As Single
       Dim duree As Single
     
     
       temps_debut = Timer
     
     
     
     
    axA = G * (((MB * (xB - xA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    ayA = G * (((MB * (yB - yA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - yA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    azA = G * (((MB * (zB - zA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (zC - zA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    axB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    ayB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    azB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    axC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    ayC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    azC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
     
     
     
     
     Range("V" & i).Value = axA
     Range("W" & i).Value = ayA
     Range("X" & i).Value = azA
     Range("Y" & i).Value = axB
     Range("Z" & i).Value = ayB
     Range("AA" & i).Value = azB
     Range("AB" & i).Value = axC
     Range("AC" & i).Value = ayC
     Range("AD" & i).Value = azC
     
    DEMIT = Range("AE" & i).Value
     
     
     
    vxA = vxA + axA * DEMIT
    vyA = vyA + ayA * DEMIT
    vzA = vzA + azA * DEMIT
    vxB = vxB + axB * DEMIT
    vyB = vyB + ayB * DEMIT
    vzB = vzB + azB * DEMIT
    vxC = vxC + axC * DEMIT
    vyC = vyC + ayC * DEMIT
    vzC = vzC + azC * DEMIT
     
     
     Range("M" & i).Value = vxA
     Range("N" & i).Value = vyA
     Range("O" & i).Value = vzA
     Range("P" & i).Value = vxB
     Range("Q" & i).Value = vyB
     Range("R" & i).Value = vzB
     Range("S" & i).Value = vxC
     Range("T" & i).Value = vyC
     Range("U" & i).Value = vzC
     
     UserForm1.Repaint
     
     UserForm1.Label10.Caption = vxA
     UserForm1.Label11.Caption = vyA
     UserForm1.Label12.Caption = vzA
     UserForm1.Label13.Caption = vxB
     UserForm1.Label14.Caption = vyB
     UserForm1.Label15.Caption = vzB
     UserForm1.Label16.Caption = vxC
     UserForm1.Label17.Caption = vyC
     UserForm1.Label18.Caption = vzC
     
     
     
     SignAntexA = UserForm1.Label28.Caption
     SignAnteyA = UserForm1.Label29.Caption
     SignAntezA = UserForm1.Label30.Caption
     SignAntexB = UserForm1.Label31.Caption
     SignAnteyB = UserForm1.Label32.Caption
     SignAntezB = UserForm1.Label33.Caption
     SignAntexC = UserForm1.Label34.Caption
     SignAnteyC = UserForm1.Label35.Caption
     SignAntezC = UserForm1.Label36.Caption
     
     
    If vxA - Range("B41").Value > 0 Then
     UserForm1.Label28.Caption = "+"
     Else
     UserForm1.Label28.Caption = "-"
     End If
     
     
     If vyA - Range("B42").Value > 0 Then
     UserForm1.Label29.Caption = "+"
     Else
     UserForm1.Label29.Caption = "-"
      End If
     
     
     If vzA - Range("B43").Value > 0 Then
     UserForm1.Label30.Caption = "+"
     Else
     UserForm1.Label30.Caption = "-"
      End If
     
     
     If vxB - Range("B45").Value > 0 Then
     UserForm1.Label31.Caption = "+"
     Else
     UserForm1.Label31.Caption = "-"
     End If
     
     
     If vyB - Range("B46").Value > 0 Then
     UserForm1.Label32.Caption = "+"
     Else
     UserForm1.Label32.Caption = "-"
      End If
     
     
     If vzB - Range("B47").Value > 0 Then
     UserForm1.Label33.Caption = "+"
     Else
     UserForm1.Label33.Caption = "-"
     End If
     
     
     If vxC - Range("B49").Value > 0 Then
     UserForm1.Label34.Caption = "+"
     Else
     UserForm1.Label34.Caption = "-"
     End If
     
     
     If vyC - Range("B50").Value > 0 Then
     UserForm1.Label35.Caption = "+"
     Else
     UserForm1.Label35.Caption = "-"
      End If
     
     
     If vzC - Range("B51").Value > 0 Then
     UserForm1.Label36.Caption = "+"
     Else
     UserForm1.Label36.Caption = "-"
     End If
     
     
     
     
     
     T = Range("AE" & i + 1).Value
     
     xA = xA + vxA * T
     yA = yA + vyA * T
     zA = zA + vzA * T
     xB = xB + vxB * T
     yB = yB + vyB * T
     zB = zB + vzB * T
     xC = xC + vxC * T
     yC = yC + vyC * T
     zC = zC + vzC * T
     
     Application.ScreenUpdating = True
     
     Range("D" & i).Value = xA
     Range("E" & i).Value = yA
     Range("F" & i).Value = zA
     Range("G" & i).Value = xB
     Range("H" & i).Value = yB
     Range("I" & i).Value = zB
     Range("J" & i).Value = xC
     Range("K" & i).Value = yC
     Range("L" & i).Value = zC
     
     
     
     xA = Range("D" & i).Value
     yA = Range("E" & i).Value
     zA = Range("F" & i).Value
     xB = Range("G" & i).Value
     yB = Range("H" & i).Value
     zB = Range("I" & i).Value
     xC = Range("J" & i).Value
     yC = Range("K" & i).Value
     zC = Range("L" & i).Value
     
     
     
     
       duree = Timer - temps_debut
     
     
     
     
       Range("B8").Value = Format(duree / 86400, "hh:mm:ss,ms")
       Range("B9").Value = Format(duree * jusk / 86400, "hh:mm:ss,ms")
     
     Application.ScreenUpdating = False
     
     
     
      i = i + 1
     
     
      Wend
     
      j = i
     
    jusk = Range("B10").Value
    While j <= jusk
     
     
     Range("D" & j).Select
     
     
       Range("B11").Value = (ActiveCell.Row) / jusk * 100
     
    Application.ScreenUpdating = False
     
     
    axA = G * (((MB * (xB - xA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    ayA = G * (((MB * (yB - yA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - yA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    azA = G * (((MB * (zB - zA)) / ((((xB - xA) ^ 2 + (yB - yA) ^ 2 + (zB - zA) ^ 2) ^ 1 / 2) ^ 3) + (MC * (zC - zA)) / ((((xC - xA) ^ 2 + (yC - yA) ^ 2 + (zC - zA) ^ 2) ^ 1 / 2) ^ 3)))
    axB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    ayB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (yC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    azB = G * (((MA * (xA - xB)) / ((((xA - xB) ^ 2 + (yA - yB) ^ 2 + (zA - zB) ^ 2) ^ 1 / 2) ^ 3) + (MC * (xC - xB)) / ((((xC - xB) ^ 2 + (yC - yB) ^ 2 + (zC - zB) ^ 2) ^ 1 / 2) ^ 3)))
    axC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    ayC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
    azC = G * (((MA * (xA - xC)) / ((((xA - xC) ^ 2 + (yA - yC) ^ 2 + (zA - zC) ^ 2) ^ 1 / 2) ^ 3) + (MB * (xB - xC)) / ((((xB - xC) ^ 2 + (yB - yC) ^ 2 + (zB - zC) ^ 2) ^ 1 / 2) ^ 3)))
     
     Range("V" & j).Value = axA
     Range("W" & j).Value = ayA
     Range("X" & j).Value = azA
     Range("Y" & j).Value = axB
     Range("Z" & j).Value = ayB
     Range("AA" & j).Value = azB
     Range("AB" & j).Value = axC
     Range("AC" & j).Value = ayC
     Range("AD" & j).Value = azC
     
    DEMIT = Range("AE" & j).Value
     
    vxA = vxA + axA * DEMIT
    vyA = vyA + ayA * DEMIT
    vzA = vzA + azA * DEMIT
    vxB = vxB + axB * DEMIT
    vyB = vyB + ayB * DEMIT
    vzB = vzB + azB * DEMIT
    vxC = vxC + axC * DEMIT
    vyC = vyC + ayC * DEMIT
    vzC = vzC + azC * DEMIT
     
     Range("M" & j).Value = vxA
     Range("N" & j).Value = vyA
     Range("O" & j).Value = vzA
     Range("P" & j).Value = vxB
     Range("Q" & j).Value = vyB
     Range("R" & j).Value = vzB
     Range("S" & j).Value = vxC
     Range("T" & j).Value = vyC
     Range("U" & j).Value = vzC
     
     UserForm1.Repaint
     
     UserForm1.Label10.Caption = vxA
     UserForm1.Label11.Caption = vyA
     UserForm1.Label12.Caption = vzA
     UserForm1.Label13.Caption = vxB
     UserForm1.Label14.Caption = vyB
     UserForm1.Label15.Caption = vzB
     UserForm1.Label16.Caption = vxC
     UserForm1.Label17.Caption = vyC
     UserForm1.Label18.Caption = vzC
     
      SignAntexA = UserForm1.Label28.Caption
     SignAnteyA = UserForm1.Label29.Caption
     SignAntezA = UserForm1.Label30.Caption
     SignAntexB = UserForm1.Label31.Caption
     SignAnteyB = UserForm1.Label32.Caption
     SignAntezB = UserForm1.Label33.Caption
     SignAntexC = UserForm1.Label34.Caption
     SignAnteyC = UserForm1.Label35.Caption
     SignAntezC = UserForm1.Label36.Caption
     
     
    If vxA - Range("B41").Value > 0 Then
     UserForm1.Label28.Caption = "+"
     Else
     UserForm1.Label28.Caption = "-"
     End If
    If SignAntexA <> UserForm1.Label28.Caption Then
     UserForm1.Label28.ForeColor = RGB(255, 0, 0)
     End If
     
     If vyA - Range("B42").Value > 0 Then
     UserForm1.Label29.Caption = "+"
     Else
     UserForm1.Label29.Caption = "-"
      End If
    If SignAnteyA <> UserForm1.Label29.Caption Then
     UserForm1.Label29.ForeColor = RGB(255, 0, 0)
     End If
     
     If vzA - Range("B43").Value > 0 Then
     UserForm1.Label30.Caption = "+"
     Else
     UserForm1.Label30.Caption = "-"
      End If
    If SignAntezA <> UserForm1.Label30.Caption Then
     UserForm1.Label30.ForeColor = RGB(255, 0, 0)
     End If
     
     If vxB - Range("B45").Value > 0 Then
     UserForm1.Label31.Caption = "+"
     Else
     UserForm1.Label31.Caption = "-"
     End If
    If SignAntexB <> UserForm1.Label31.Caption Then
     UserForm1.Label31.ForeColor = RGB(255, 0, 0)
     End If
     
     If vyB - Range("B46").Value > 0 Then
     UserForm1.Label32.Caption = "+"
     Else
     UserForm1.Label32.Caption = "-"
      End If
    If SignAnteyB <> UserForm1.Label32.Caption Then
     UserForm1.Label32.ForeColor = RGB(255, 0, 0)
     End If
     
     If vzB - Range("B47").Value > 0 Then
     UserForm1.Label33.Caption = "+"
     Else
     UserForm1.Label33.Caption = "-"
     End If
    If SignAntezB <> UserForm1.Label33.Caption Then
     UserForm1.Label33.ForeColor = RGB(255, 0, 0)
     End If
     
     If vxC - Range("B49").Value > 0 Then
     UserForm1.Label34.Caption = "+"
     Else
     UserForm1.Label34.Caption = "-"
     End If
    If SignAntexC <> UserForm1.Label34.Caption Then
     UserForm1.Label34.ForeColor = RGB(255, 0, 0)
     End If
     
     If vyC - Range("B50").Value > 0 Then
     UserForm1.Label35.Caption = "+"
     Else
     UserForm1.Label35.Caption = "-"
      End If
    If SignAnteyC <> UserForm1.Label35.Caption Then
     UserForm1.Label35.ForeColor = RGB(255, 0, 0)
     End If
     
     If vzC - Range("B51").Value > 0 Then
     UserForm1.Label36.Caption = "+"
     Else
     UserForm1.Label36.Caption = "-"
     End If
    If SignAntezC <> UserForm1.Label36.Caption Then
     UserForm1.Label36.ForeColor = RGB(255, 0, 0)
     End If
     
    DoEvents
     
    UserForm1.TextBox1.Value = UserForm1.TextBox1.Value
    MvxA = UserForm1.TextBox1.Value
    vxA = vxA + MvxA
     
    UserForm1.TextBox2.Value = UserForm1.TextBox2.Value
    MvyA = UserForm1.TextBox2.Value
    vyA = vyA + MvyA
     
    UserForm1.TextBox3.Value = UserForm1.TextBox3.Value
    MvzA = UserForm1.TextBox3.Value
    vzA = vzA + MvzA
     
    UserForm1.TextBox4.Value = UserForm1.TextBox4.Value
    MvxB = UserForm1.TextBox4.Value
    vxB = vxB + MvxB
     
    UserForm1.TextBox5.Value = UserForm1.TextBox5.Value
    MvyB = UserForm1.TextBox5.Value
    vyB = vyB + MvyB
     
    UserForm1.TextBox6.Value = UserForm1.TextBox6.Value
    MvzB = UserForm1.TextBox6.Value
    vzB = vzB + MvzB
     
    UserForm1.TextBox7.Value = UserForm1.TextBox7.Value
    MvxC = UserForm1.TextBox7.Value
    vxC = vxC + MvxC
     
    UserForm1.TextBox8.Value = UserForm1.TextBox8.Value
    Mvyc = UserForm1.TextBox8.Value
    vyC = vyC + Mvyc
     
    UserForm1.TextBox9.Value = UserForm1.TextBox9.Value
    MvzC = UserForm1.TextBox9.Value
    vzC = vzC + MvzC
     
     
     
     
     
     
     T = Range("AE" & j + 1).Value
     
     xA = xA + vxA * T
     yA = yA + vyA * T
     zA = zA + vzA * T
     xB = xB + vxB * T
     yB = yB + vyB * T
     zB = zB + vzB * T
     xC = xC + vxC * T
     yC = yC + vyC * T
     zC = zC + vzC * T
     
     Application.ScreenUpdating = True
     
     Range("D" & j).Value = xA
     Range("E" & j).Value = yA
     Range("F" & j).Value = zA
     Range("G" & j).Value = xB
     Range("H" & j).Value = yB
     Range("I" & j).Value = zB
     Range("J" & j).Value = xC
     Range("K" & j).Value = yC
     Range("L" & j).Value = zC
     
     Application.ScreenUpdating = False
     
     j = j + 1
     
     
     
     
     
     
     Wend
     
     
     XdureeX = Timer - XtempsX_debut
     
     
     
       Range("C9").Value = Format(XdureeX / 86400, "hh:mm:ss,ms")
     
     
     
     
     
     
    Else
     
     
    MsgBox Range("A10").Value & " doit être " & Range("A11").Value & " " & Range("A12").Value
    Exit Sub
     
     
    End If
     
     
    ThisWorkbook.Save
     
     
    End Sub
    C'est tout bon.....à ceci près que je n'arrive pas à rentrer de valeurs négatives
    Cela doit venir de mes déclaration en , quel déclaration dois-je rédiger pour pouvoir inscrire des "Doubles négatifs"?

    Non, j'ai compris, le problème vient du fait que la variable de ma textbox déclarée en double se modifie dès que je tape "-" et donc plante.

    Comment contourner la chose?

    Comment indiquer au USF qu'il faut attendre que toute la valeur soit entrée dans le textbox et pas seulement le "-" du premier caractère?

  10. #10
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut
    J'ai essayé d emettre un commandbutton "VALIDER":

    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
    If UserForm1.CommandButton2.Value = "Faux" Then
     
    UserForm1.TextBox1.Value = UserForm1.TextBox1.Value
    MvxA = UserForm1.TextBox1.Value
    vxA = vxA + MvxA
     
    UserForm1.TextBox2.Value = UserForm1.TextBox2.Value
    MvyA = UserForm1.TextBox2.Value
    vyA = vyA + MvyA
     
    UserForm1.TextBox3.Value = UserForm1.TextBox3.Value
    MvzA = UserForm1.TextBox3.Value
    vzA = vzA + MvzA
     
    UserForm1.TextBox4.Value = UserForm1.TextBox4.Value
    MvxB = UserForm1.TextBox4.Value
    vxB = vxB + MvxB
     
    UserForm1.TextBox5.Value = UserForm1.TextBox5.Value
    MvyB = UserForm1.TextBox5.Value
    vyB = vyB + MvyB
     
    UserForm1.TextBox6.Value = UserForm1.TextBox6.Value
    MvzB = UserForm1.TextBox6.Value
    vzB = vzB + MvzB
     
    UserForm1.TextBox7.Value = UserForm1.TextBox7.Value
    MvxC = UserForm1.TextBox7.Value
    vxC = vxC + MvxC
     
    UserForm1.TextBox8.Value = UserForm1.TextBox8.Value
    Mvyc = UserForm1.TextBox8.Value
    vyC = vyC + Mvyc
     
    UserForm1.TextBox9.Value = UserForm1.TextBox9.Value
    MvzC = UserForm1.TextBox9.Value
    vzC = vzC + MvzC
     
    End If
    Dans le code de la macro, je ne peux toujours pas entrer de valeur négative et dans le code du commandbutton, je n'arrive pas à faire tenir compte de la modification le code de la marco

  11. #11
    Membre Expert Avatar de Transitoire
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Décembre 2017
    Messages
    733
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Décembre 2017
    Messages : 733
    Par défaut
    Bonjour ce bout de code permet d'éviter l'erreur du "-"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    If TextBox1.Value = "-" Or TextBox1.Value = "" Then
    Else
    Range("A1").Value = CDbl(TextBox1.Value)
    End If
    Voir l'intervention de @Pijaku sur ce post. https://www.developpez.net/forums/d1.../#post10561373
    Enfin j'ai testé, ça marche sur mon ordinateur.
    Cordialement

  12. #12
    Membre éprouvé
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    1 150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2012
    Messages : 1 150
    Par défaut
    Parfait, merci, ça fonctionne bien!!!!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 33
    Dernier message: 28/04/2010, 04h44
  2. Sauvegarder les modifications sur une variable
    Par maaike dans le forum VBA Access
    Réponses: 5
    Dernier message: 21/08/2007, 23h28
  3. Modification d'une variable & rafraichissement! HELP!
    Par u115php dans le forum Langage
    Réponses: 4
    Dernier message: 09/09/2006, 01h04
  4. [Eclipse 3.1]Modification d'une variable
    Par thecaptain dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 18/01/2006, 09h17
  5. Réponses: 2
    Dernier message: 29/08/2005, 16h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo