Message d'erreur tant que la do loop ne se finit pas

Bonjour à tous!

Je cherche à indiquer le le message d'erreur "Error ! 1]Cash out must be equal or over to 0 . 2] Cash out must be inferior to account balance." tant que la boucle do loop until fonctionne.

1] Voici mon fichier xlsm ci-dessous.

2] Voici mon code ci-dessous.

Option Explicit

Sub compute_tax_crypto2()
    Dim number_of_session As Single
    Dim cash_in As Single
    Dim profit_or_loss As Single
    Dim account_balance As Single
    Dim cash_out As Single
    Dim end_session_profit_or_loss_before_tax As Single
    Dim tax_percentage As Single
    tax_percentage = 30
    Dim end_session_profit_or_loss_after_tax As Single
    Dim tax_amount As Single
    Dim i As Integer
    Dim last_row As Long
    Dim lr As Single

    Worksheets("Sheet1").Activate
    last_row = Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row
    number_of_session = InputBox("How many sessions did you trade?")
    Cells(last_row + 1, 1) = number_of_session
    For i = last_row + 1 To last_row + number_of_session
        Cells(1, 9) = i - last_row
        cash_in = InputBox("How many cash-in?")
        Cells(i, 2).Value = cash_in
        profit_or_loss = InputBox("How many profit or loss?")
        Cells(i, 3).Value = profit_or_loss
        account_balance = cash_in + profit_or_loss
        Cells(i, 4).Value = account_balance
        Do
            cash_out = VBA.InputBox("How many cash out?")
        Loop Until cash_out <= account_balance And cash_out >= 0
        MsgBox "The amount of cash out is under amount of account balance and cash out is equal or over 0, great!"
        Cells(i, 5).Value = cash_out
        end_session_profit_or_loss_before_tax = cash_out - (cash_in * (cash_out / account_balance))
        Cells(i, 6).Value = end_session_profit_or_loss_before_tax
        If Cells(i, 6).Value <= 0 Then
            Cells(i, 7).Value = 0
            MsgBox "The end session profit or loss after tax is : " & 0
        Else
            end_session_profit_or_loss_after_tax = (tax_percentage / 100) * end_session_profit_or_loss_before_tax
            Cells(i, 7).Value = end_session_profit_or_loss_after_tax
            MsgBox "The end session profit or loss after tax is : " & end_session_profit_or_loss_after_tax
            tax_amount = end_session_profit_or_loss_before_tax - end_session_profit_or_loss_after_tax
            Cells(i, 8).Value = tax_amount
        End If
    Next i
    lr = Cells(Rows.Count, 8).End(xlUp).Row
    Cells(Rows.Count, 7).End(xlUp).Offset(1, 0).Select
    ActiveCell.Offset(0, 0).Value = "Total amount of tax"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Formula = "=sum(H2:H" & lr & ")"

End Sub

Bonsoir,

un essai, mais je n'y comprend rien en anglais... C'est bien de l'anglais ?

TextMsg = "How many cash out ?"
        Do
            cash_out = VBA.InputBox(TextMsg)
            TextMsg = "Error !" & Chr(10) & "1]Cash out must be equal or over to 0." & Chr(10) & "2] Cash out must be inferior to account balance." & Chr(10) & Chr(10) & "How many cash out ?"  
        Loop Until cash_out <= account_balance And cash_out >= 0

@ bientôt

LouReeD

C'est parfait, fonctionne parfaitement!!!! Merci, merci!

Rechercher des sujets similaires à "message erreur tant que loop finit pas"