Coloring A Text Box in an Excel Form

cgmackenzie

New Member
Joined
Apr 1, 2015
Messages
35
Hi All,

I'm trying to create a form in which users enter their information into text boxes. I'd like each text box to have a red fill until information is entered. Once information is entered into the box I'd like there to be no fill. Any ideas?

Thanks for the help!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,708
Office Version
  1. 2016
Platform
  1. Windows
Behind the form you would something along this line for when the form is initialized or activated.

Private Sub UserForm_Initialize()
Me.TextBox1.BackColor = vbRed
End Sub

Then each textbox has events and shown below is an example when a textbox has something in it to colour it white.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.TextBox1.Value <> "" Then Me.TextBox1.BackColor = vbWhite

End Sub
 
Upvote 0

cgmackenzie

New Member
Joined
Apr 1, 2015
Messages
35
Thanks Trevor,

I'm a VBA beginner.

Can you please give me a step by step including the exact code (so I can copy and paste) and how I should enter it into VBA.

Thanks,

Colin
 
Upvote 0

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,708
Office Version
  1. 2016
Platform
  1. Windows
Colin when you say your are creating a form do you mean you are using a VBA form? if you are using a worksheet then you would use conditional formatting from the home Tab. Select the cells and first then use the equal to option and see this example.

Excel Workbook
G
3q
4e
5f
6
7
8
9
10
11
12
13
14
15
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G31. / Cell Value equal to =""Abc
G41. / Cell Value equal to =""Abc
G51. / Cell Value equal to =""Abc
G61. / Cell Value equal to =""Abc
G71. / Cell Value equal to =""Abc
G81. / Cell Value equal to =""Abc
G91. / Cell Value equal to =""Abc
G101. / Cell Value equal to =""Abc
G111. / Cell Value equal to =""Abc
G121. / Cell Value equal to =""Abc
G131. / Cell Value equal to =""Abc
G141. / Cell Value equal to =""Abc
G151. / Cell Value equal to =""Abc
 
Upvote 0

Forum statistics

Threads
1,195,619
Messages
6,010,736
Members
441,567
Latest member
Flitbee

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
Top