Solved VBA Textbox font color

April 19, 2010 at 16:27:53
Specs: Windows XP
I have an Excel VBA form that I use for data entry and data retrieval. (People don't need to know how to use Excel.) One field in the form compares the current date to a previous date stored in a cell. If it is more than 2 weeks old, I want to see the textbox font in red. I can use conditional formatting to change the font color in the CELL, but not in the userform's TEXTBOX. Basically, when the user finds a record with a date requiring attention, I want it to be noticed. There must be some conditional code I can use. Any help is appreciated.

See More: VBA Textbox font color

Report •

April 20, 2010 at 04:12:34
✔ Best Answer

Here is some code that will change the color of the text in a Textbox on a User Form, based on the difference in dates between Today and a date in a worksheet cell:

If Worksheets("Sheet1").Range("A2").Value < Int(Now()) - 14 Then
    Me.TextBox1.ForeColor = RGB(255, 0, 0)
    Me.TextBox1.ForeColor = RGB(0, 0, 0)
End If
Me.TextBox1.Value = Worksheets("Sheet1").Range("A2").Text

You will need to change the worksheet name and cell reference and the name of the Textbox on the user form.

The code could go in the user form Activate section.

Hope this was what you were looking for.


Report •

April 20, 2010 at 13:42:05
Thank you so much. I knew it could happen some how.
I appreciate your help.

Report •

April 21, 2010 at 05:00:56

You're very Welcome, and thanks for the feedback.



Report •

Related Solutions

Ask Question