Conditional Formatting Fields

J Carvell

Board Regular
Joined
Sep 20, 2005
Messages
55
I am trying to find a way of turning a field on a form (which is formatted to short date) different colours depending on the day of the week. For example Monday=white, Tuesday=Yellow, Wednesday=Green etc.

Unfortunately conditional formatting doesn't give me enough conditions. I have tried to write some code found in other messages but it doesn't seem to work.

Can anyone help?
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
You can do something like this:

1. In design view, get the form's properties and go to the Events tab. In the Current event, double-click the blank line. You'll see Event Procedure. Click here, then click the Builder (...) button to go to the code window. You'll need to put in code like this --

Code:
Select Case Weekday([YourDateField])
    Case 1
       [YourDateField].BackColor=255 'red
    Case 2
       [YourDateField].BackColor=65536 'yellow, I think
    'keep going for the other 5 weekdays

End Select
To work out what numbers to use, open any form and select a range of background colours from the palette. After each one, check the BackColor property and write it down.

By putting the code into the Form_Current event, you get the formatting to apply every time you go a to new record. You'll need to ensure that the BackStyle property for the control is Solid. By default it's Transparent, and no colour change will be visible.
If you need to fire the change when a field changes, leave the Form_Current code as it is. But go to the AfterUpdate event of the control you want to use as the trigger, and type Form_Current in the code for the sub.

Denis
 

Watch MrExcel Video

Forum statistics

Threads
1,122,450
Messages
5,596,221
Members
414,046
Latest member
mbeutler1203

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