Rekursiv!
13.04.2023 20:33:54
Yal
Hallo Tim,
wenn Du in "TextBox56_Change" den Wert von TextBox56 änderst, dann musst Du die Ereignis-Ausführung blockieren, sonst wird diese Prozedure immer wieder ausgerufen: Application.EnableEvents = False
Allgemein: vermeide Wiederholung, setze einen Standard, oder Default, und behandle nur die Ausnahmen.
Private Sub TextBox56_Change()
'3 mal TextBox37 und 12 mal TextBox56. Welche sollte man als "With" platzieren?
If Not IsNumeric(TextBox37.Value) Then Exit Sub
Application.EnableEvents = False 'gegen endlose Schleife
With TextBox56
'Default: wird immer gemacht
.Font.Name = "Wingdings 3"
.Font.Size = "10"
If CDbl(TextBox37.Value) = 0 Then
.Text = "o"
.ForeColor = vbWhite
ElseIf CDbl(TextBox37.Value) > 0 Then
.Text = "h"
.ForeColor = vbRed
Else ' 0
.Text = "i"
.ForeColor = vbGreen
End If
End With
Application.EnableEvents = True
End Sub
Private Sub UserForm_Initialize()
Dim Ctrl As Control
Dim Elt
Application.EnableEvents = False 'gegen endlose Schleife
UrsachenUserFormAlle.BackColor = RGB(31, 78, 121)
For Each Elt In Split("1:G1 2:H1 3:G2 4:H2 5:I2 6:J2 17:J7 18:H7")
Controls("Textbox" & Split(Elt, ":")(0)) = Worksheets("Pivot").Range(Split(Elt, ":")(1)).Value
Next
TextBox37.Text = CStr(CDbl(TextBox17.Text) - CDbl(TextBox27.Text))
TextBox56.Text = TextBox37.Text
For Each Ctrl In Controls
'setze Standardwert
Ctrl.BackColor = RGB(32, 78, 121)
Ctrl.ForeColor = vbWhite
Ctrl.Font.Name = "Arial"
Ctrl.Font.Size = "10"
'behandle Ausnahmen
If TypeOf Ctrl Is MSForms.TextBox Then
If InStr(1, "1;2;3;4;5;6", Right(Ctrl.Name, 1)) Then
Ctrl.Font.Name = "Arial" 'eigentlich nicht Arial, aber die Information fehlt
Ctrl.SpecialEffect = 0
Else
Ctrl.BackColor = RGB(32, 78, 121)
Ctrl.Font.Size = "12"
Ctrl.SpecialEffect = 0
End If
End If
If TypeOf Ctrl Is MSForms.Frame Then
Ctrl.Font.Bold = True
Ctrl.Font.Size = "12"
End If
Next
Application.EnableEvents = True
End Sub
VG
Yal