Ich habe eine UserForm entworfen auf der in Labels verschiedene Werte angezeigt werden. Über 2 OptionButtons kann der User die Ansicht wählen: absolut oder prozentual.
Die Werte sollen rot sein wenn sie 0 sind.
Bei den absoluten Werten funktioniert das auch einwandfrei - aber nicht bei den Prozent-Werten !!!!
Wo ist mein Fehler ?
Hier das Listing des Moduls in dem die Werte geprüft werden:
Option Explicit
Public
Sub FORM1Berechnen()
Dim iabsolut As Integer
Dim iprozent As Integer
If FORM1.optBut2.Value = -1 Then
On Error Resume Next
With FORM1
.lbl1.Caption = Format([2005!M1029], "##0.0 %")
.lbl2.Caption = Format([2005!N1029], "##0.0 %")
.lbl3.Caption = Format([2005!O1029], "##0.0 %")
.lbl69.Caption = Format([2005!O1028], "##0.0 %")
.lbl70.Caption = Format([2005!P1028], "##0.0 %")
.lbl71.Caption = Format([2005!Q1028], "##0.0 %")
End With
'FORMATIERUNG
For iprozent = 1 To 71
If FORM1.Controls("lbl" & iprozent).Caption < 0 Then
FORM1.Controls("lbl" & iprozent).ForeColor = &HFF&
Else
FORM1.Controls("lbl" & iprozent).ForeColor = &H8000&
End If
Next iprozent
End If
If FORM1.optBut1.Value = -1 Then
' Hier werden die Werte aus dem Excel-Sheet geholt
On Error Resume Next
With FORM1
.lbl1.Caption = Format([2005!M1014], "#,##0")
.lbl2.Caption = Format([2005!N1014], "#,##0")
.lbl3.Caption = Format([2005!O1014], "#,##0")
.lbl69.Caption = Format([2005!O1013], "#,##0")
.lbl70.Caption = Format([2005!P1013], "#,##0")
.lbl71.Caption = Format([2005!Q1013], "#,##0")
End With
For iabsolut = 1 To 71
If FORM1.Controls("lbl" & iabsolut).Caption < 0 Then
FORM1.Controls("lbl" & iabsolut).ForeColor = &HFF&
Else
FORM1.Controls("lbl" & iabsolut).ForeColor = &H8000&
End If
Next iabsolut
End If 'BLOCK1
FORM1.Show
End Sub