RoVo1211
Gebruiker
- Lid geworden
- 24 feb 2024
- Berichten
- 114
- Besturingssysteem
- Windows 11
- Office versie
- Office 365
Code:
With txtVerschilx
.Value = FormatPercent(Sheets(1).[S6].Value, 3)
If txtVerschil3.Value >= 0.05 Then
.BackColor = RGB(0, 128, 0)
.ForeColor = vbWhite
ElseIf txtVerschil3.Value >= 0.01 And txtVerschil3.Value < 0.05 Then
.BackColor = RGB(0, 192, 0)
.ForeColor = vbWhite
ElseIf txtVerschil3.Value >= 0.005 And txtVerschil3.Value < 0.01 Then
.BackColor = RGB(192, 255, 192)
.ForeColor = vbBlack
ElseIf txtVerschil3.Value >= 0.0001 And txtVerschil3.Value < 0.005 Then 'Tussen 0.5-1%
.BackColor = RGB(224, 255, 224)
.ForeColor = vbBlack
ElseIf txtVerschil3.Value >= -0.0001 And txtVerschil3.Value < 0.0001 Then 'Ongeveer 0
.BackColor = RGB(0, 192, 255)
.ForeColor = vbYellow
ElseIf txtVerschil3.Value >= -0.005 And txtVerschil3.Value < -0.0001 Then 'Tussen -0.5% en 0%
.Font.Bold = False
.ForeColor = vbBlack
.BackColor = RGB(255, 224, 224)
ElseIf txtVerschil3.Value >= -0.01 And txtVerschil3.Value < -0.005 Then 'Tussen -1 en -0.5%
.BackColor = RGB(255, 176, 176)
.ForeColor = vbBlack
ElseIf txtVerschil3.Value >= -0.05 And txtVerschil3.Value < -0.01 Then 'Tussen -5 en -1%
.BackColor = RGB(255, 0, 0)
.ForeColor = vbWhite
ElseIf txtVerschil3.Value < -0.05 Then 'Minder -5%
.BackColor = RGB(128, 0, 0)
.ForeColor = vbWhite
End If
End With
Ik heb deze With...End With-constructie staan bij alle "Verschil"-velden staan, maar elk veld krijgt dezelfde achtergrondkleur terwijl bij een negatief resultaat het veld een rode tint moet krijgen en bij een positief resultaat een groene tint als achtergrond moet krijgen. Wat doe ik fout?