Fill Cell with Colour

  • Re: if statement


    Here is code to color cell by clicking :




    This code requires the use of a CommandButton:


    Code
    Private Sub TextBox1_Change()
    If Val(Replace(Me.TextBox1.Value, "%", "")) < 46 Then
    Me.TextBox1.BackColor = vbGreen
    ElseIf Val(Replace(Me.TextBox1.Value, "%", "")) > 45 And Val(Replace(Me.TextBox1.Value, "%", "")) < 76 Then
    Me.TextBox1.BackColor = vbYellow
    Else: Me.TextBox1.BackColor = vbRed
    End If
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!