XL 2010 Calcul possible dans la zone de liste pour le débit et le crédit lors d'une recherche basée sur la zone de texte

Mody200

XLDnaute Junior
Bonjour
Je veux le calcul dans la zone de liste de la colonne BALANCE lorsque je recherche l'ID dans la deuxième colonne de la zone de liste de la zone de texte 4, je dois alors modifier le calcul.
Je sélectionne d’abord le nom de la feuille dans combobox1 et je remplirai les données dans la zone de liste et je remplirai la dernière ligne de la feuille dans
zone de texte 1,2,3 maintenant, lorsque vous recherchez l'identifiant dans la deuxième colonne de la dernière partie comme dans la photo2, il doit être calculé comme ceci
La première ligne de la zone de liste de la colonne (BALANCE)=0-2200=-2200
La deuxième ligne de la zone de liste de la colonne (BALANCE)=-2200+(-4200)=-6400
La troisième ligne de la zone de liste de la colonne (BALANCE) = -6400 + 7000 - 6200 = 57400
La dernière ligne (TOT) de la zone de liste doit être modifiée et les colonnes INPUT et OUTPUT doivent être ajoutées et BALANCE doit être soustraite par INPUT de OUTPUT (70000-12600=57400).

D'abord lorsque vous sélectionnez la feuille dans combobox1
VB:
Option Explicit
Option Compare Text

Private Data, Temp, Crit As String, i As Long, lr As Long, ii As Long, x As Long
Dim ws As Worksheet


Private Sub ComboBox1_Change()
'ActiveSheet.Visible = True
 If ComboBox1.Value <> "" Then
  TextBox1.Value = ""
  TextBox2.Value = ""
  TextBox3.Value = ""
  CommandButton1.Enabled = True
 
  End If
  If ComboBox1.Value = "" Then ListBox1.Clear
  If ComboBox1.Value = "" Then TextBox1.Value = "": TextBox2.Value = "": TextBox3.Value = ""
  If ComboBox1.Value <> "" Then
  TextBox1.Visible = True: TextBox2.Visible = True: TextBox3.Visible = True
 
  If ComboBox1.Value = "" Then Exit Sub

Set ws = Sheets(ComboBox1.Value)

ws.Activate

With ws
lr = .Range("A" & Rows.Count).End(xlUp).Row
TextBox1.Value = .Range("C" & lr).Value
TextBox2.Value = .Range("D" & lr).Value
TextBox3.Value = .Range("E" & lr).Value
If TextBox3.Value < 0 Then
TextBox3.ForeColor = vbRed
Else: TextBox3.ForeColor = vbBlack
End If
End With

  Call LBoxPop

 
 End If

End Sub
Private Sub TextBox1_Change()
TextBox1.Value = Format(TextBox1, "#,##0.00")
 Call LBoxPop
End Sub

Private Sub TextBox2_Change()
TextBox2.Value = Format(TextBox2, "#,##0.00")
End Sub
Private Sub TextBox3_Change()
TextBox3.Value = Format(TextBox3, "#,##0.00")
End Sub

Private Sub UserForm_Initialize()
 
 Crit = ""
  Dim i As Long
  For i = 1 To Sheets.Count
   If Sheets(i).Name <> "DATA" And Sheets(i).Name <> "MAIN" Then
   ComboBox1.AddItem Sheets(i).Name
   End If
  Next
 
  If ComboBox1.ListIndex > -1 Then
    Set ws = Sheets(ComboBox1.Value)
    Call LBoxPop
    
  End If
  If ComboBox1.Value = "" Or ComboBox1.Value <> "" Then CommandButton1.Enabled = False
 
      ListBox1.SetFocus



 
End Sub
Private Sub LBoxPop()

    Dim r          As Long, c As Long
    Dim Data()     As Variant
    Dim rng        As Range
    Dim va
    
   Debug.Print ws.Name
    Set rng = ws.Cells(1, 1).CurrentRegion
'
    Data = ws.Cells(1, 1).CurrentRegion.Value
    
    For i = 1 To UBound(Data, 1)
        Data(i, 1) = Format(Data(i, 1), "yyyy-mm-dd")
    Next
 For i = 1 To UBound(Data, 1)
        Data(i, 3) = Format(Data(i, 3), "#,##0.00")
        Data(i, 4) = Format(Data(i, 4), "#,##0.00")
        Data(i, 5) = Format(Data(i, 5), "#,##0.00")
    Next
    With UserForm1.ListBox1
        .ColumnCount = 5
        .columnWidths = "90;300;120;120;100"
        .List = Data
    End With
    
    
        For i = ListBox1.ListCount - 1 To 0 Step -1

    Debug.Print i, ListBox1.List(i, 0)
      If ListBox1.List(i, 0) <> "" Then
        ListBox1.ListIndex = i
        Exit For
      End If
    Next i
 


 
End Sub
 

Pièces jointes

  • 2.PNG
    2.PNG
    18.8 KB · Affichages: 15
  • 1.PNG
    1.PNG
    27.2 KB · Affichages: 16

Discussions similaires

Réponses
6
Affichages
244

Statistiques des forums

Discussions
312 208
Messages
2 086 257
Membres
103 167
dernier inscrit
miriame