I am trying to change the colour of the textbox in a userform based on the value in the textbox compared to the cell value in C10, ie if textbox value is 9 and cell value is 10 the colour is green
the below code make the textbox the same colour regardless of values entered
Private Sub TextBox16_Change()
If ActiveSheet.Range("C10").Value > TextBox16.Value Then
Me.TextBox16.ForeColor = &H8000000D
Me.TextBox16.BackColor = &HFF&
Else
Me.TextBox16.ForeColor = &HFF&
Me.TextBox16.BackColor = &H8000000D
End If
End Sub
Thanks,
Try this If ActiveSheet.Range("C10").Value > CLng(TextBox16.Value) Then
But you'll need to add some error handling because when textbox gets empty, or some other value than number you'll end up with 'type mismath' error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.