XL 2010 Boucles - Délai de récupération - Finance

Olivier1978

XLDnaute Nouveau
Bonjour David et bonjour à tous,

Je travaille sur un fichier financier qui concerne le délai de récupération d'un investissement.

J'aurai besoin de faire deux boucles. J'ai essayé avec la fonction "si", la fonction "min" mais cela ne répond pas à mon besoin.
Pour "vous" cela va vous faire rire, mais moi je n'y arrive pas.

Je vous joins le fichier, j'ai tout expliqué dedans.

Le code que vous me proposerez, me permettra d'être "meilleur" sur les "boucles".

Je vous remercie pour votre aide.

Bon week-end à tous,

Olivier
 

Pièces jointes

  • Boucle DR.xlsm
    15.8 KB · Affichages: 7
Solution
Re,
"Just for the fun", avec une seule boucle :
VB:
Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Fin: If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C3:C5,C14:G15")) Is Nothing Then
         Dim C%, InvestInit, PlusProche, NbJours%, Trouvé%
         Application.ScreenUpdating = False
         Application.EnableEvents = False
         InvestInit = [C5]: NbJours = [C3]: Trouvé = 0: PlusProche = 0
         For C = 3 To 7
            If Cells(15, C) >= InvestInit And Trouvé = 0 Then
                [L16] = Cells(14, C) / NbJours
                Trouvé = 1
            End If
            If Cells(15, C) <= InvestInit Then
                If InvestInit - Cells(15, C) > PlusProche Then PlusProche = Cells(15, C)...

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonjour Olivier,
Un essai en PJ avec :
VB:
Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Fin: If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C3:C5,C14:G15")) Is Nothing Then
         Dim C%, InvestInit, PlusProche
         Application.ScreenUpdating = False
         Application.EnableEvents = False
         InvestInit = [C5]: NbJours = [C3]
         For C = 3 To 7
            If Cells(15, C) >= InvestInit Then
                [L16] = Cells(14, C) / NbJours
                Exit For
            End If
         Next C
         PlusProche = 0
         For C = 3 To 7
            If Cells(15, C) <= InvestInit Then
                If InvestInit - Cells(15, C) > PlusProche Then PlusProche = Cells(15, C)
            End If
         Next C
         [L17] = InvestInit - PlusProche
    End If
Fin:
Application.EnableEvents = True
End Sub
 

Pièces jointes

  • Boucle DR.xlsm
    18.6 KB · Affichages: 2

sylvanu

XLDnaute Barbatruc
Supporter XLD
Re,
"Just for the fun", avec une seule boucle :
VB:
Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Fin: If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C3:C5,C14:G15")) Is Nothing Then
         Dim C%, InvestInit, PlusProche, NbJours%, Trouvé%
         Application.ScreenUpdating = False
         Application.EnableEvents = False
         InvestInit = [C5]: NbJours = [C3]: Trouvé = 0: PlusProche = 0
         For C = 3 To 7
            If Cells(15, C) >= InvestInit And Trouvé = 0 Then
                [L16] = Cells(14, C) / NbJours
                Trouvé = 1
            End If
            If Cells(15, C) <= InvestInit Then
                If InvestInit - Cells(15, C) > PlusProche Then PlusProche = Cells(15, C)
            End If
         Next C
         [L17] = InvestInit - PlusProche
    End If
Fin:
Application.EnableEvents = True
End Sub
 

Pièces jointes

  • Boucle DR V2.xlsm
    18.7 KB · Affichages: 3

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 685
Messages
2 090 940
Membres
104 703
dernier inscrit
romla937