I tried to make a textbox in a userform changes its background, green if less than 100% and red if more or equal to 100%. So far I made 2 different codes and I got 2 different results!
The first code is:
Private Sub CommandButton1_Click()
TextBox1.Value = Sheets("Sheet1").Range("I9").Value
TextBox1.Value = Format(TextBox1.Value, "0.00")
If TextBox1.Value >= "1" Then
TextBox1.BackColor = vbRed
Else: TextBox1.BackColor = vbGreen
End If
End Sub
And I got the correct result, but the format is not in percentage.
The second code is:
Private Sub CommandButton2_Click()
TextBox2.Value = Sheets("Sheet1").Range("I9").Value
TextBox2.Value = Format(TextBox2.Value, "0.00%")
If TextBox2.Value >= "1" Then
TextBox2.BackColor = vbRed
Else: TextBox2.BackColor = vbGreen
End If
End Sub
I managed to change the format to percentage, but I got the background color wrong.
What is wrong with my code in the second one? I did the same thing, except that I changed the format from 0.00 to 0.00%, and somehow I got the background the other way around.
Is there any way for me to rectify this? I want to display it as percentage, and get the background color to be green if its less than 100%, and red if equal or more than 100%.
Thank you in advance.
Bookmarks