Changing the color of a cell in report

susc10

New Member
Joined
Jul 3, 2012
Messages
2
Hello,

I'm trying to change the background color of a cell called Year FL based on the value in it. I can't use conditional formatting because I have more than 3 conditions (Access 2007). I've set the back style to be normal and I'm using VBA code. This is my code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Select Case [Year FL]
Case Is > 2000
[Year FL].BackColor = 52479 'orange
Case Is > 5000
[Year FL].BackColor = 255 'red
Case Is < -2000
[Year FL].BackColor = 52479
Case Is < -5000
[Year FL].BackColor = 255
End Select
End Sub


*Sorry I'm new here. Not sure how to format code for the forums.

Anyway, the gist of it is that if the value in the cell is greater than $5000 or less than ($5,000), the background will be red. If the value is between 2,000 and 5,000 (or -2,000 and -5,000), the background is orange. Otherwise it is white. However, my code from above is not working the way I want it to. The format of the cell itself is currency with no decimal places and negative numbers are within parentheses. Thank you for any help.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,277
Messages
6,171,148
Members
452,382
Latest member
RonChand

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