Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1556to1560
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Textbox_Exit für mehrere Boxen Vereinfachen

Textbox_Exit für mehrere Boxen Vereinfachen
19.05.2017 10:02:48
Carsten
Hey,
gibt es ne elegantere Variante für meinen Code hier? Soweit klappt das gut allerdings doch recht unübersichtlich das ganze. :D
Im Prinzip soll er den Code für 8 Textboxen ausführen also bei 8 Verschiednen Exits habe es mit ner Do Schleife probiert allerdings hat er natürlich nur wenn ich aus Textbox 1 raus bin die Werte übernommen.
  • 
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 1
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  7000  _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  6000  _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  5000  _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  4000  _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  3000  _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  2000  _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value  1000  _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub
    

    Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 2
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub

    Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 3
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub

    Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 4
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub

    Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 5
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub

    Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 6
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub

    Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 7
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub

    Private Sub TextBox8_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim i As Integer
    i = 8
    If Controls("TextBox" & i).Value > 8000 Then
    TextBox16.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 7000 _
    Then TextBox15.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 6000 _
    Then TextBox14.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 5000 _
    Then TextBox13.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 4000 _
    Then TextBox12.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 3000 _
    Then TextBox11.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 2000 _
    Then TextBox10.Value = Controls("TextBox" & i).Value
    ElseIf Controls("TextBox" & i).Value 1000 _
    Then TextBox9.Value = Controls("TextBox" & i).Value
    End If
    End Sub


  • 1
    Beitrag zum Forumthread
    Beitrag zu diesem Forumthread

    Betreff
    Datum
    Anwender
    Anzeige
    AW: Textbox_Exit für mehrere Boxen Vereinfachen
    19.05.2017 10:33:29
    ChrisL
    Hi Carsten
    Wohin kommen die Werte z.B. 2000 oder 3000 (sind weder grösser noch kleiner als X).
    Zum Thema "Klassenmodul" müsstest du dich selber einlesen, aber hier schon einmal eine Vereinfachung:
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(1)
    End Sub
    
    Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(2)
    End Sub
    
    Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(3)
    End Sub
    
    Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(4)
    End Sub
    
    Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(5)
    End Sub
    
    Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(6)
    End Sub
    
    Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(7)
    End Sub
    
    Private Sub TextBox8_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Call Uebertrag(8)
    End Sub
    

    Private Sub Uebertrag(iTB As Byte)
    Dim i As Long
    With Controls("TextBox" & iTB)
    If .Value 

    cu
    Chris
    Anzeige

    Links zu Excel-Dialogen

    Beliebteste Forumthreads (12 Monate)

    Anzeige

    Beliebteste Forumthreads (12 Monate)

    Anzeige
    Anzeige
    Anzeige