Close Window
Free Ebook
Get Your Free Excel
Top 15 Excel Tutorials from
Instant Access!

Change Textbox Backcolor

Hi all,

I'm trying to change the back color on a textbox.

example for 1 textbox entry among others that I will be conditionally changing the back color.

Private Sub UserForm_Initialize()

Dim lngYellow As Long, lngWhite As Long
 lngYellow = RGB(252, 248, 61)
lngWhite = RGB(255, 255, 255)

With Me.TextBox1
.BackColor = lngWhite
 End With

If .TextBox1.Value = "" Then Me.TextBox1.BackColor = lngYellow

Any help to fix this is appreciated.
I don't know how, but during the process of trying this, I've changed the textbox1 back color to yellow.
Everything that I've tried to set it back to white has failed.

Free Excel Courses

Similar Excel Tutorials

How to have a button in a UserForm disabled until the desired event occurs. For instance, you could prevent a "subm ...

Let's create a working UserForm in Excel. This is a step-by-step tutorial that shows you everything you need to do ...

How to loop through all controls in a UserForm; this allows you to do things like get values from the controls or t ...

This tutorial gives you an overview of what a UserForm Control is and how to add them to your form. Sections: What ...

Helpful Excel Macros

- This macro will highlight all cells in excel which are not empty. This means that if a cell contains formulas, text, nu

- This macro will highlight all of the cells in a worksheet which contain a formula. The first one listed will highlight

- This free Excel UDF allows you to output the color of a cell in text format or as that color's index number. Also note

- This free Excel macro will highlight every other row in a selection of cells with a color that is specified within the m

- This macro will highlight the row and column of the active cell. This will fill the row of the active cell with a solid

Similar Topics

Hi Guys,

Could you be so kind as to provide some code that will enable me to display a text box on a userform rounded up to 1 decimal place.

Where am I going wrong....
it calculates the number entered in textbox1 and divides it by a value that changes in cell O26 but the answer is in about 8 or more decimel places.
Only need like 65.3 as an answer not 65.277756942

This is the code ive used.

Private Sub CommandButton1_Click()

TextBox2.Value = Val(TextBox1.Value) / Range("O26").Value

End Sub

Is there a way I can use conditional formatting or something to change the color of the cell once I enter a value or text into that cell? For example if I currently have the A2 cell color as a gray color, and I enter information into A2 can I have it set to automatically change to no fill or any other color without having to click out of the cell, back into it, and then clicking the button?? Does that make sense??? Can someone help me?

How do I get the colors to change automatically when I use a drop down list.
Per say here is what I am trying to do

If a certain "word" is used from the drop down list I want the background of
that cell to change its color to "green." And if later I change the "word" to
another from the drop down list, it will change it's color to a specified

The drop down list that I use was created from cells that have the colors
already in the "word", but I do not know how to make the list show the colors
so it puts the word & color automatically in the drop down list to the cell
with the drop down (if that makes any sense).

If there is a way, please spell it out simple enough for me to understand,
as I don't know fully the capabilities of formulas or vba.

I have a large database with names, addresses etc. When I try to make changes
to the email address, like change the font color or change on letter, Excel
tries to email the address. If I click in the formula bar to make the
changes, it automatically changes it back to all blue text and underlined. I
have tried to format all of the cells as "Text" to show as entered, but it
doesnt work. PLEASE HELP

Is it possible to change the color of text using a formula, such as an IF
statement? What I have in mind is something like this (stated simply): If
cells B9 or N9 or Z9 or AL9 are blank, do nothing, else color text in cell S4

I have cells in a column, some colored yellow, some not. I am trying to use
the SUMIF function to sum only the cells in the range that are colored. Can
this be done? Can I enter something in the "criteria" part of the formula
that can do this?


I also tried to use the CELL function's color feature, but I couldn't get it
to work right. I don't know how to get Excel to recognize if a cell is
colored in a formula.

It might just be that I don't know what this means in Help:

"color" --> 1 if the cell is formatted in color for negative values;
otherwise returns 0 (zero).

Can anyone help?

Hi there,

I have a spreadsheet with some cells setup with a drop-down list containing
Y, N or N/A

This is being used on a TabletPC but if I make a mistake or need to change
back to a blank field I have to invoke the soft keyboard, activate the cell
and hit backspace then close the soft keyboard - quite a long-winded
procedure just to change an incorrect choice!

What I would like to do is add a blank to the list so if I have to revert
back to a blank I can just use the stylus to choose a blank from the chooser

How do I add the option of inputting a blank from the Data Validation List
bearing in mind I am using the Data Validation Source box for entering my
choices directly and not specifying a range of cells?

I have tried adding "" and even a space to no avail.

Although not a betting man I would wager there is a simple 'fix' for this
but things are only simple if you know how in the first instance! ;^)

Thanks & regards,

I have a userform containing a multicolumn listbox (ListBox1) and textbox (txtSelectedJobNumber).

When a user clicks on a line in the listbox I want to automatically copy the text in the 3rd column of the selected line to the textbox.

If anyone could provide code which would allow me to do this I would be grateful



I have a textbox in my userform where anything typed in the box is entered into cell A2 in my worksheet. However, multiple lines of text are not properly displayed in my worksheet. I have enabled MultiLine and EnterKeyBehaviour in the properties window of the textbox so I can type multiple lines in my textbox. The problem is that when I press the button to enter the text from my txtbox to cell A2, the cell doesn't actually display the text in separate lines. It just places a square symbol in the place that enter should have been pressed and the text should have been split into separate lines.

How can I get the separate lines of text in my textbox to be properly displayed in a cell? Thanks for your help in advance..

I'm trying to use conditional formatting to highlight phone calls that came in between certain hours.

The call times are in the custom format h:mm, although it could easily be changed to an Excel time format. I'm using Excel 2002. I want the cell to have a different fill color if it falls within particular time frames.

Example: If the call came in between 22:00 and 23:59 color is light green.
If the call came in between 23:59 and 08:00 the color is yellow.

Example spreadsheet is attached.

Thanks in advance.

Hi guys,

I was wondering if it is possible to change the color of a command button after it's been clicked?

This is to allow the user to identify which buttons have already been clicked.


I know this question has been asked a bajillion times, so I apologize for the redundancy.

I am working with an Excel spreadsheet and saving it as a .csv file in order to upload to an application that parses out the .csv data as transactions. The system requires .csv files, so this is how I need to save my doc (with this extension). I have been successful at preventing Excel from coverting that long number into scientific format. I have saved as a TXT file, pasted the longer number and it displays correctly. That is all good. But I have to save as a .csv. So if I do that, close the Excel window, and then open again (as the .csv file), the numbers are back to being displayed in scientific format. I have tried creating an Excel doc from scratch and entering text in Text format, to see if this created a cleaner file. But again, the second I save as .csv, close the window and then open that file up again, that dang scientific format is back.

Does anyone have any idea of how to work around this? Once I have successfully gotten the numbers to display as the long-chain number, how can I get them to "stick" so that they don't revert back to scientific format when I reopen the file?

Thanks so much for your help!

Thought I'd start this topic since there seem to be a number of topics where the answer seems to be to use one of the above rather than other. Thought I'd kick off with my 2 cents' worth.

I have a userform with frames containing textboxes. The user enters a currency value and once they leave the control, then a protected textbox next to it shows the corresponding value in SEK. I started off using the exit event but ran into 2 problems.

If you tabbed out of the last textbox in the frame, the exit event never kicked in (this is documented in other topics but took some time to find). This resulted in me using the exit event for all except the last textbox in the frame that used afterupdate instead I then discovered that the exit events didn't kick in if, instead of tabbing out of the field, I deliberately placed focus in a control elsewhere on the form. Changing the event from exit to afterupdate corrected this. My question then is ... could you guys document in this topic when you would/must use the exit rather than the afterupdate event (or vice-versa).


I'm using some basic code below in an on Workbook Open event to format cells with a value less then 2 and less than 1 with a particular color.

The code works, but it really slows my worksheet down when opening. Is there better way to write this? Thanks!


Dim myRange As Range
Dim cell As Range
Set myRange = Range("V6:V50000")
 For Each cell In myRange
 If cell.Value < 2 Then cell.Font.ColorIndex = 5
 If cell.Value < 1 Then cell.Font.ColorIndex = 3

Good mornng - I am new to the forum - my name is Jena

My question is this - I have a large spreadsheet with multiple columns of information. I want to sort it by a certain column. I know how to do this. My question is, once I'm done with my work I want to sort it back to the original "sort" but I'm not sure how they have it sorted. I've tried to figure out how they have it sorted but can't. Is there some way to go back to the original sort?

Thank you for your anticipated help.


I am using Excel 2007 and suddenly I can no longer filter by color. The option is greyed out and so is the sort by Color option. Does anyone have any idea why this would happen?

Thanks in advance.

Hello, what I would like to do is take a portion of a sheet..... So the cells I want to mirror are in the proposal sheet cells B32 x F51. And then mirror the exact duplicate copy to another sheet. The other sheet should have those same values at A20 X G39. What I am trying to do is have a sheet that has skus, prices, and so forth and then when I add,delete, merge, color, or do anything to the cell on the "proposal creation" sheet I want it to mirror only a specific cells to another sheet that is "salesman copy" that we will print to clients. So this way ont he proposal copy a salesman can insert rows or even change the color of the cells and then have it mirror exactly the same on the "salesman copy" which is what we will print for clients. Thank you.

Can you put a diagonal line in a cell and then color one part of it one color and the ther part of it another color?

Does anyone know how to automatically go back to the cell I was working on (meaning, the cell I last worked on) before I run a macro?



I am looking to change how an active cell is viewed. For instance when you are looking at your spreadsheet you can see the active cell has a thin black border around it. I would like to change the border to a thicker one and change the color to blue or red. I am trying to make it easier to the eye so when you are working on a large spreadsheet it is immediatly apparent where you are to avoid squinting.

If anyone can help me please let me know.

This is probably an easy question for most of you, but it's killing me. I tried searching before I posted this, but the suggestions given didn't seem to work for me.

I need to look up data from a cell on one Excel sheet, compare it to a list on a 2nd sheet and when they equal, take a value from a different column on the 2nd sheet and drop it back on the 1st sheet. Since that's a horrible explanation, let me try explaining it this way:

Sheet 1
Column A has a long list of code type 1s
Column E has a long list of code type 2s

Sheet 2
Cell C2 has code 1
Cell E2 needs code 2

I know it should take an index/match function, but nothing I try is working. What I'm trying is the following formula in Cell E2 of sheet 2:

=INDEX('Sheet 1'!A:A,MATCH(C2,'Sheet 1"!E:E,0),5)

But all I get is no result. What's driving me bonkers is that if I copy everything over to a single sheet, that formula works fine.

I have a requirement to change the panes in excel.
My excel file will contain more than one tab.
I have to free the first two lines in all the tabs except the first one.
I tried the following code.


ActiveWindow.FreezePanes = True

But in this I have to change the Active Worksheets in VBA, Which I want to avoid.
Is there any method to achieve this without selecting the cells.
Something like

xlsobj.Worksheets(1).Rows("1:2").FreezePanes = True

Hi folks,

My problem is Tab no longer moves your active cell selection one to the right. It now moves to the last cell in your spreadsheet to the right (similar to CTRL+Arrow Key Right).

I seem to remember this being a simple setting you can change, but was unable to find it myself, or search the web for the way out. So my last result is asking the experts .

Do any of you know how to make it so Tab goes back to just moving one cell to the right again?

Thanks in advanced.

I have a template that automatically populates the date field with the
current date when opened, using today(). Users then Save As to have an
archive copy of their spreadsheet. However, when they go back to access
their saved sheet, the date changes from the created date to the current
date. How do I stop this in Excel?

I know that Word lets you do this by changing the code from {DATE} to
{CREATEDATE}, but I can't find a similar setting in Excel.

Please help and thank you!

Hello everyone, I am new to this forum and have been using excel for about 3 years. I have learned alot but still can not figure out how to make numbers add up in one box like a running total. Meaning, If I have a list and in the list is one cell for each item say like cell a1 is for a can of coke and cell a2 is for a car tire and so on,and i want to keep a running total by adding a number to cell a1 or a2 like say "3 i.e. 3 tires or cans of coke" and later that day i come back and need to add 2 more i want to be able to just click on the cell a1 or a2 and enter the number 2 and the cell would add the number in it to the number im adding to it to show a result of 5 tires or whatever. I am sorry If i am not asking the question in an understandable manor but its the best way I can think to ask anyways, any help would be appreciated, Thanks in advance.


Related pages

how do you do a tick in excelbracket randomizerexcel ctrl fhow to continue numbering in exceldual axis chart excelexcel filter based on cell valuecreating a stacked column chart in excelexport excel to notepadtoo many different cell formats excel errormsgbox new linecut string in excelduplicate finder excelexcel freight trackingalphanumeric sequencingstem and leaf plot for decimalshow to delete a named rangeweeknum formulaexcell auto grouphow to plot pareto chart in excelsquare wave exceladodb recordset vba excelqfx readerexcel vba for loopsexcel convert string to formulacreate kml file from excelexcel xirrmortgage constant formula excelhow to enable macros on excelms access vba delete recordconvert billion rupees to croresfooty tipping spreadsheethow to lock single cells in excelradio button in excel 2010vba excel closecalculating fv in excelexcel compare two listsauto update pivot tabletwo axis chart excel 2007excel dsnauto cursor moverhow to add alternate rows in excelsqrt in excelconvert decimal minutes to minutes and secondsmeld score calculationhow to split first name and last name in excelstring manipulation excelstacked and clustered chart excelrandom generator for excelpercentage increase decrease formulavba excel last rowautomation error 440calculating averages worksheetnetworkdays functionharveys ballscell color function excelexcel vba union4x6 index cardconcatenate in vbahow to use minverse in excelexcel userforms for data entryvba trim not workingvlookup text formatcopy vlookup formula to other cellsexcel drag formula shortcuthow to solve matrix in excelmicrosoft visual basic run-time error 1004outlook to excel exportadd secondary axis in excel 2010excel cumulative formuladde stock price16 team double elimination bracket excelmultiply matrix excelanalysis toolpak excel 2010 downloadmilitary time conversion minutes to hundredths