Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change a cell format based on information in the cell

Status
Not open for further replies.

ozzieugene

Programmer
Jun 1, 2003
4
0
0
SG
Hi is it possible to write a macro which will change the appearance of the cell (such as the colour of the words, the cell colour) depending on the content of the cell.

For example, test results (out of 100), a score of 40 will result in the number 40 being in red and highlighted and the cell colour in green.
 
Hiya

You could have somthing as simple as the following contected to a button. You can obviously add to this by add 'elseif (statement)'.

I hope this helps.

Andy

Code:


Sub Button1_Click()
If ActiveCell.Value = "40" Then
Selection.Font.ColorIndex = 3
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
Else: ActiveCell.Select
End If

End Sub
 
Hi ozzieugene,

Yes, it would be possible to write a macro but a better solution would be to use Conditional Formatting - available from the Format menu.

Take a look and come back if you need help using it.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top