Textbox1 color

S

Shazi

Hi Everyone,

I put a textbox1 in userform1, the textbox1 is link to sheet1, with
B5.

My userform get the value from B5, when it loads. I want to make a
function like this that, if the value is < 50 then it would be Red,
otherwise it will be White.

I arrange like this, but its not working.

I request to guide me accordingly.


Private Sub TextBox1_AfterUpdate()

If Val(TextBox1.Text) < 50 Then
TextBox1.BackColor = vbRed
Else
TextBox1.BackColor = vbWhite
End If

End Sub



Private Sub UserForm_Initialize()

TextBox1.Value = Sheets("Sheet1").Range("B5")

End Sub




Thanks and regards.

Shahzad
 
B

Bob Phillips

Private Sub TextBox1_AfterUpdate()
Call ColourTextbox
End Sub

Private Sub UserForm_Activate()
TextBox1.Value = Sheets("Sheet1").Range("B5")
Call ColourTextbox
End Sub

Private Sub ColourTextbox()

If Val(TextBox1.Text) < 50 Then
TextBox1.BackColor = vbRed
Else
TextBox1.BackColor = vbWhite
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top