How do I cange text box color on click

Dark0Prince

Active Member
Joined
Feb 17, 2016
Messages
433
I'd like to toggle through 3 colors red yellow and green. On click I'd like to be able to change the color of a text box to these colors. I'm up for ideas so far I've been able only to change the color of a text box based on a formula or the color of the cell with a click, but the cells are too big.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.BackColor = RGB(255, 255, 255) Then
TextBox1.BackColor = vbRed
End If
If TextBox1.BackColor = vbRed Then
TextBox1.BackColor = vbBlue
End If
If TextBox1.BackColor = vbBlue Then
TextBox1.BackColor = vbYellow
End If
If TextBox1.BackColor = vbYellow Then
TextBox1.BackColor = RGB(255, 255, 255)
End If

End Sub
This is what I wrote so far, but no luck it just gets to white then stops.
 
Upvote 0
If the textbox is on a userform try
Code:
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
   If TextBox1.BackColor = -2147483643 Then
      TextBox1.BackColor = vbRed
   ElseIf TextBox1.BackColor = vbRed Then
      TextBox1.BackColor = vbBlue
   ElseIf TextBox1.BackColor = vbBlue Then
      TextBox1.BackColor = vbYellow
   ElseIf TextBox1.BackColor = vbYellow Then
      TextBox1.BackColor = -2147483643
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,011
Messages
6,128,265
Members
449,436
Latest member
blaineSpartan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top