Problème de Dépassement de capacité et temps de calcul important

Fermé
amiro2017 Messages postés 193 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 - 5 mars 2017 à 23:29
amiro2017 Messages postés 193 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 - 6 mars 2017 à 13:29
Bonsoir le forum,
j'ai un problème lors de l'exécution de mon code VBA d'une part j'ai un temps de calcul long et d'autre part lors j'excute un autre procédure un message s'affiché
"dépassement de capacité" sachant que mon code contient des formule de calculs et surtout la fonction monte carlo qui nécessite un temps important d'éxécution!

s'il vous plaît aidez-moi à résoudre ce problème et merci d'avance
A voir également:

1 réponse

f894009 Messages postés 17241 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 19 février 2025 1 713
6 mars 2017 à 08:19
Bonjour,

Certe, mais sans votre code, pouvons rien voir
0
amiro2017 Messages postés 193 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 1
6 mars 2017 à 09:10
Private Sub CommandButton5_Click()
Application.ScreenUpdating = False
Dim derniereLigne As Integer
Dim i, j, T As Integer

Dim m, sigma, m1, sigma1 As Double
Dim V1(), V2(), D1(), D2() As Double
Worksheets("feuil1").Activate
derniereLigne = Range("B" & Rows.Count).End(xlUp).Row
ReDim V1(1 To 253, 1 To 1)
ReDim V2(1 To 253, 1 To 1)
ReDim D1(1 To 10000, 2 To 252)
ReDim D2(1 To 10000, 2 To 252)

For i = derniereLigne - 252 To derniereLigne - 1
V1(derniereLigne - i + 1, 1) = Application.WorksheetFunction.Ln(Cells(i, 2) / Cells(i + 1, 2))
V2(derniereLigne + 1 - i, 1) = Application.WorksheetFunction.Ln(Cells(i, 3) / Cells(i + 1, 3))
Next i
m = Application.WorksheetFunction.Median(V1)
sigma = Application.WorksheetFunction.StDev(V1)
m1 = Application.WorksheetFunction.Median(V2)
sigma1 = Application.WorksheetFunction.StDev(V2)
T = 1
For i = 2 To 252
For j = 1 To 1000
D1(j, i) = Cells(i, 2) * Exp((m - 0.5 * sigma ^ 2) * T - sigma * Application.NormInv(Rnd(), 0, 1) * Sqr(T))
D2(j, i) = Cells(i, 3) * Exp((m1 - 0.5 * sigma1 ^ 2) * T - sigma1 * Application.NormInv(Rnd(), 0, 1) * Sqr(T))
Next j
Cells(i, 5).Value = D1(1000, i)
Cells(i, 6).Value = D2(1000, i)
Next i

Dim ObjCell1(), ObjCell() As Double
ReDim ObjCell(2 To 252, 1 To 1)
ReDim ObjCell1(2 To 252, 1 To 1)
For i = 2 To 250
ObjCell1(i, 1) = 21517363.669192 * Application.WorksheetFunction.Ln(Cells(i, 2) / Cells(i + 1, 2)) + 44152744.8658505 * Application.WorksheetFunction.Ln(Cells(i, 3) / Cells(i + 1, 3))
ObjCell(i, 1) = 21517363.669192 * Application.WorksheetFunction.Ln(Cells(i, 5) / Cells(i + 1, 5)) + 44152744.8658505 * Application.WorksheetFunction.Ln(Cells(i, 6) / Cells(i + 1, 6))
Next i
m = Application.WorksheetFunction.Median(ObjCell)
sigma = Application.WorksheetFunction.StDev(ObjCell)
Worksheets("feuil2").Activate
ThisWorkbook.Worksheets("feuil2").Range("B2:B252").Value = ObjCell1
TextBox6.Text = Format(Application.WorksheetFunction.NormInv(0.99, m, sigma), "0.0000")
TextBox5.Text = Format(-WorksheetFunction.Percentile_Inc(Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row - 1), 0.01), "0.0000")
ThisWorkbook.Worksheets("feuil2").Range("E2:E252").Value = ObjCell
TextBox4.Text = Format(-WorksheetFunction.Percentile_Inc(Range("E2:E" & Range("E" & Rows.Count).End(xlUp).Row - 1), 0.01), "0.0000")
Application.Calculation = xlCalculationAutomatic
End Sub
0
yg_be Messages postés 23474 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 février 2025 1 568
Modifié par yg_be le 6/03/2017 à 09:16
bonjour, suggestions:
Dim m As Double, sigma As Double, m1 As Double, sigma1 As Double

idem autres dim
ajouter au début:
Application.Calculation = xlCalculationManual

question: sur quelle ligne as-tu l'erreur?
0
amiro2017 Messages postés 193 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 1 > yg_be Messages postés 23474 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 février 2025
6 mars 2017 à 10:00
Bonjour yg_be

je vous remercie d'abord pour votre aide , concernant l'erreur de dépassement de capacité à été résolu puisque celle ci paraît lorsque je manipule deux userform en même temps cependant même j'ajoute votre proposition je sens que le temps de calcul reste important
0
amiro2017 Messages postés 193 Date d'inscription mardi 28 février 2017 Statut Membre Dernière intervention 31 août 2017 1 > yg_be Messages postés 23474 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 19 février 2025
6 mars 2017 à 13:29
je retourne vers vous yg_be ,

il avait mainenant un problème de dépassement de la capacité dans cette ligne:
V1(i, 1) = Application.WorksheetFunction.Ln(Cells(i, 2) / Cells(i + 1, 2))
aidez moi stp!
0