macros

Tyre

Board Regular
Joined
Feb 17, 2002
Messages
79
is there a way to associate a number with a color?
for example:
when the number 1 is pressed, the cell color becoms yellow, when a 2 is pressed the cell becomes pink?
This message was edited by Tyre on 2002-03-13 05:35
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The following should work OK, paste it into the worksheet, it turns the font colour white, unless the cell colour is white, adapt as necessary :) :-

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Count > 1 Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub

Select Case Target.Value
Case 1 To 56
Target.Interior.ColorIndex = Target.Value
If Target.Value <> 2 Then _
Target.Font.ColorIndex = 2
End Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

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